0

我知道堆栈上有很多这类问题,但没有一个回答对我有帮助,所以我在这里,卡住了。

Dropbox 底部的图片链接

构建 iOS xcode 项目时出现错误。它说有重复的符号,但我似乎无法弄清楚为什么它说有重复......

正如您在我的第二个屏幕截图中看到的那样,我的构建设置中没有重复项。

我尝试了这篇文章中提供的选项,但没有一个有效:链接器命令失败,退出代码为 1(使用 -v 来查看调用)

编译器所说的重复变量位于 cellConstants.h 中,我将其导入到DNZListCell.mDNZTaskCell.m

任何帮助将不胜感激。

谢谢!!

细胞常数.h

#ifndef Donzo_cellConstants_h
#define Donzo_cellConstants_h

const float UI_CUES_MARGIN = 10.0f;
const float UI_CUES_WIDTH = 50.0f;

const float LABEL_LEFT_MARGIN = 15.0f;
const float LABEL_WIDTH = 150.0f;

const float TASK_LABEL_WIDTH = 60.0f;

#endif

DNZListCell.h

#import <UIKit/UIKit.h>
#import "DNZList.h"
#import "DNZListTableViewCellDelegate.h"


@class DNZStrikethroughLabel;
@interface DNZListCell : UITableViewCell <UITextFieldDelegate>

// The item that this cell renders
@property (nonatomic) DNZList *listItem;

// The object that acts as delegate for this cell.
@property (nonatomic, assign) id<DNZListTableViewCellDelegate> delegate;

@end

DNZListCell.m

//
//  DNZListCell.m
//  Donzo
//
//  Created by Matt Wahlig on 2/22/13.
//  Copyright (c) 2013 Matt Wahlig. All rights reserved.
//

#import "DNZListCell.h"
#import <QuartzCore/QuartzCore.h>
#import "DNZStrikethroughLabel.h"
#import "DNZShowListSegue.h"
#import "cellConstants.h"

@implementation DNZListCell {
    CGPoint _originalCenter;
    BOOL _deleteOnDragRelease;
    DNZStrikethroughLabel *_label;
    UILabel *_taskCountLabel;
    UILabel *_crossLabel;
}



- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _label = [[DNZStrikethroughLabel alloc] initWithFrame:CGRectNull];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont fontWithName:@"nevis" size:28];
        _label.backgroundColor = [UIColor clearColor];
        _label.delegate = self;
        _label.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [self addSubview:_label];
        // remove the default blue highlight for selected cells
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        _taskCountLabel = [[UILabel alloc] initWithFrame:CGRectNull];
        _taskCountLabel.font = [UIFont fontWithName:@"nevis" size:26];
        [_taskCountLabel setTextAlignment:NSTextAlignmentCenter];
        [self addSubview:_taskCountLabel];

        _crossLabel = [self createCueLabel];
        _crossLabel.text = @"\uf00d";
        _crossLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_crossLabel];

        UIPanGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];

        UITapGestureRecognizer *singleFingerTap =
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(handleSingleTap:)];
        [self addGestureRecognizer:singleFingerTap];
    }
    return self;
}



-(void)layoutSubviews {
    [super layoutSubviews];
    // ensure the gradient layers occupies the full bounds
    _label.frame = CGRectMake(LABEL_LEFT_MARGIN, 0,
                              self.bounds.size.width-LABEL_LEFT_MARGIN-TASK_LABEL_WIDTH,self.bounds.size.height);
    _taskCountLabel.frame = CGRectMake(LABEL_LEFT_MARGIN+_label.frame.size.width, 0, TASK_LABEL_WIDTH, TASK_LABEL_WIDTH);
    _crossLabel.frame = CGRectMake(self.bounds.size.width + UI_CUES_MARGIN, 0,
                                   UI_CUES_WIDTH, self.bounds.size.height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setListItem:(DNZList *)listItem {
    _listItem = listItem;
    // we must update all the visual state associated with the model item
    _label.text = [listItem.listName uppercaseString];
    _taskCountLabel.text = [NSString stringWithFormat:@"%i",listItem.taskArray.count];
    _taskCountLabel.textColor = _listItem.listColorScheme.listBackgroundColor;
    _taskCountLabel.backgroundColor = _listItem.listColorScheme.toolbarBackgroundColor;
}

-(UILabel*) createCueLabel {
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectNull];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"FontAwesome" size:28];
    label.backgroundColor = [UIColor clearColor];
    return label;
}

#pragma mark - single tap gesture methods

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
    [self.delegate listCellClicked:self];
}

#pragma mark - horizontal pan gesture methods
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
    if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
        return NO;
    }
    CGPoint translation = [gestureRecognizer translationInView:[self superview]];
    // Check for horizontal gesture
    if (fabsf(translation.x) > fabsf(translation.y)) {
        return YES;
    }
    return NO;
}

-(void)handlePan:(UIPanGestureRecognizer *)recognizer {
    // 1
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        // if the gesture has just started, record the current centre location
        _originalCenter = self.center;
    }

    // 2
    if (recognizer.state == UIGestureRecognizerStateChanged) {
        // translate the center
        CGPoint translation = [recognizer translationInView:self];
        self.center = CGPointMake(_originalCenter.x + translation.x, _originalCenter.y);
        // determine whether the item has been dragged far enough to initiate a delete / complete
        _deleteOnDragRelease = self.frame.origin.x < -_crossLabel.frame.size.width; //-self.frame.size.width / 2;

        // fade the contextual cues
        float cueAlpha = fabsf(self.frame.origin.x) / _crossLabel.frame.size.width;//(self.frame.size.width / 2);
        _crossLabel.alpha = cueAlpha;

        // indicate when the item have been pulled far enough to invoke the given action
        _crossLabel.textColor = _deleteOnDragRelease ?
        [UIColor colorWithRed:242/255.0 green:108/255.0 blue:79/255.0 alpha:1] : [UIColor whiteColor];

    }

    // 3
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        // the frame this cell would have had before being dragged
        CGRect originalFrame = CGRectMake(0, self.frame.origin.y,
                                          self.bounds.size.width, self.bounds.size.height);
        if (!_deleteOnDragRelease) {
            // if the item is not being deleted, snap back to the original location
            [UIView animateWithDuration:0.2
                             animations:^{
                                 self.frame = originalFrame;
                             }
             ];
        }
        if (_deleteOnDragRelease) {
            // notify the delegate that this item should be deleted
            [self.delegate listItemDeleted:self.listItem];
        }
    }

}

#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    // close the keyboard on enter
    [textField resignFirstResponder];
    return NO;
}
//
//-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//    // disable editing of completed to-do items
//    return !self.listItem.completed;
//}

-(void)textFieldDidBeginEditing:(UITextField *)textField {
    [self.delegate cellDidBeginEditing:self];
}

-(void)textFieldDidEndEditing:(UITextField *)textField {

    // set the model object state when an edit has complete
    self.listItem.listName = textField.text;

    [self.delegate cellDidEndEditing:self];
}

@end

DNZTaskCell.h

#import <UIKit/UIKit.h>
#import "DNZTask.h"
#import "DNZTaskTableViewCellDelegate.h"


@class DNZStrikethroughLabel;
@interface DNZTaskCell : UITableViewCell <UITextFieldDelegate>

// The item that this cell renders
@property (nonatomic) DNZTask *taskItem;

// The object that acts as delegate for this cell.
@property (nonatomic, assign) id<DNZTaskTableViewCellDelegate> delegate;

@end

DNZTaskCell.m

#import "DNZTaskCell.h"
#import <QuartzCore/QuartzCore.h>
#import "DNZStrikethroughLabel.h"
#import "cellConstants.h"

@implementation DNZTaskCell {
    CGPoint _originalCenter;
    BOOL _deleteOnDragRelease;
    DNZStrikethroughLabel *_label;
    UILabel *_crossLabel;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        _label = [[DNZStrikethroughLabel alloc] initWithFrame:CGRectNull];
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont fontWithName:@"nevis" size:28];
        _label.backgroundColor = [UIColor clearColor];
        _label.delegate = self;
        _label.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        [self addSubview:_label];
        // remove the default blue highlight for selected cells
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        _crossLabel = [self createCueLabel];
        _crossLabel.text = @"\uf00d";
        _crossLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_crossLabel];

        UIPanGestureRecognizer* recognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
        recognizer.delegate = self;
        [self addGestureRecognizer:recognizer];

        UITapGestureRecognizer *singleFingerTap =
        [[UITapGestureRecognizer alloc] initWithTarget:self
                                                action:@selector(handleSingleTap:)];
        [self addGestureRecognizer:singleFingerTap];
    }
    return self;
}

-(void)layoutSubviews {
    [super layoutSubviews];
    // ensure the gradient layers occupies the full bounds
    _label.frame = CGRectMake(LABEL_LEFT_MARGIN, 0,
                              self.bounds.size.width-LABEL_LEFT_MARGIN-TASK_LABEL_WIDTH,self.bounds.size.height);
    _crossLabel.frame = CGRectMake(self.bounds.size.width + UI_CUES_MARGIN, 0,
                                   UI_CUES_WIDTH, self.bounds.size.height);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setTaskItem:(DNZTask *)taskItem {
    _taskItem = taskItem;
    // we must update all the visual state associated with the model item
    _label.text = [taskItem.taskName uppercaseString];

}

-(UILabel*) createCueLabel {
    UILabel* label = [[UILabel alloc] initWithFrame:CGRectNull];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"FontAwesome" size:28];
    label.backgroundColor = [UIColor clearColor];
    return label;
}

#pragma mark - single tap gesture methods

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
    [self.delegate taskCellClicked:self];
}

#pragma mark - horizontal pan gesture methods
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
    if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]) {
        return NO;
    }
    CGPoint translation = [gestureRecognizer translationInView:[self superview]];
    // Check for horizontal gesture
    if (fabsf(translation.x) > fabsf(translation.y)) {
        return YES;
    }
    return NO;
}

-(void)handlePan:(UIPanGestureRecognizer *)recognizer {
    // 1
    if (recognizer.state == UIGestureRecognizerStateBegan) {
        // if the gesture has just started, record the current centre location
        _originalCenter = self.center;
    }

    // 2
    if (recognizer.state == UIGestureRecognizerStateChanged) {
        // translate the center
        CGPoint translation = [recognizer translationInView:self];
        self.center = CGPointMake(_originalCenter.x + translation.x, _originalCenter.y);
        // determine whether the item has been dragged far enough to initiate a delete / complete
        _deleteOnDragRelease = self.frame.origin.x < -_crossLabel.frame.size.width; //-self.frame.size.width / 2;

        // fade the contextual cues
        float cueAlpha = fabsf(self.frame.origin.x) / _crossLabel.frame.size.width;//(self.frame.size.width / 2);
        _crossLabel.alpha = cueAlpha;

        // indicate when the item have been pulled far enough to invoke the given action
        _crossLabel.textColor = _deleteOnDragRelease ?
        [UIColor colorWithRed:242/255.0 green:108/255.0 blue:79/255.0 alpha:1] : [UIColor whiteColor];

    }

    // 3
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        // the frame this cell would have had before being dragged
        CGRect originalFrame = CGRectMake(0, self.frame.origin.y,
                                          self.bounds.size.width, self.bounds.size.height);
        if (!_deleteOnDragRelease) {
            // if the item is not being deleted, snap back to the original location
            [UIView animateWithDuration:0.2
                             animations:^{
                                 self.frame = originalFrame;
                             }
             ];
        }
        if (_deleteOnDragRelease) {
            // notify the delegate that this item should be deleted
            [self.delegate taskItemDeleted:self.taskItem];
        }
    }

}

#pragma mark - UITextFieldDelegate
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    // close the keyboard on enter
    [textField resignFirstResponder];
    return NO;
}
//
//-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
//    // disable editing of completed to-do items
//    return !self.listItem.completed;
//}

-(void)textFieldDidBeginEditing:(UITextField *)textField {
    [self.delegate cellDidBeginEditing:self];
}

-(void)textFieldDidEndEditing:(UITextField *)textField {

    // set the model object state when an edit has complete
    self.taskItem.taskName = textField.text;

    [self.delegate cellDidEndEditing:self];
}

@end

错误截图

Xcode 错误

https://www.dropbox.com/s/ppvb722gteaaxfi/xcode_Error.png

构建设置

https://www.dropbox.com/s/cljczenwyc7i5pr/build-settings.png
4

1 回答 1

0

问题是你使用cellConstants.h

您需要 extern 变量,这样您就不会在每次导入文件时都对其进行新的声明。

也创建一个cellConstants.m

更改您cellConstants.h的所有变量为extern

细胞常数.m

const float UI_CUES_MARGIN = 10.0f;

细胞常数.h

extern float UI_CUES_MARGIN;
于 2013-02-24T00:35:33.147 回答