我实事求是地设置了uitextfields,uisegmentedcontrols一个的tableview等自定义UITableViewCells UITextField强或弱引用?
这里的
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];
}
}
我对所有这些文本字段建立资源并将它们分配给新创建的领域作为一个例子你可以看到。
我的问题是我应该使用(非原子,强)还是(非原子,弱)?
@property(nonatomic, weak) UITextField *idField;
//Or
@property(nonatomic, strong) UITextField *idField;
idField一次只能是一个文本字段。你是否试图在你的财产中存储一个引用到最近创建的文本字段?你最终想要达到什么目标?如果你的意图是保持对你创建的所有文本字段的引用,那么这是不行的。 – geraldWilliam
我有一个idField,upcField,别名字段,说明字段等。我这样做,以便我可以阅读文本字段。即[self.idField.text]它现在正常工作。我只是想知道我应该使用强还是弱 – Hackmodford