【发布时间】:2012-10-15 17:29:19
【问题描述】:
我正在务实地设置一个带有 uitextfields、uisegmentedcontrols 等的 tableview。
这是一个例子
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//NSLog(@"creating a new %@", CellIdentifier);
if([CellIdentifier isEqualToString:@"ID"]) {
UITextField *newTextField = [[UITextField alloc] initWithFrame:CGRectMake(80, 5, 215, 34)];
self.idField = newTextField;
[cell addSubview:self.idField];
}
}
我正在为所有这些文本字段创建属性,并将它们分配给新创建的字段,如您所见。
我的问题是我应该使用 (nonatomic, strong) 还是 (nonatomic, weak) ?
@property(nonatomic, weak) UITextField *idField;
//Or
@property(nonatomic, strong) UITextField *idField;
【问题讨论】:
-
idField 一次只能是一个文本字段。您是否尝试在您的属性中存储对最近创建的文本字段的引用?你最终想要达到什么目标?如果您的意图是保留对您创建的所有文本字段的引用,则不这样做。
-
我有一个 idField、upcField、Alias Field、Description 字段等。我这样做是为了可以阅读文本字段。即 [self.idField.text] 它现在可以正常工作。我只是想知道我应该使用强还是弱
标签: objective-c ios uitableview automatic-ref-counting