【发布时间】:2012-04-18 18:23:39
【问题描述】:
@property (nonatomic, strong) NSMutableArray *authorMutableArray;
- (id)init {
self = [super init];
if (self) {
self.authorMutableArray = [[NSMutableArray alloc] initWithObjects:@"First Row", @"Second Row", nil];
for (NSString *string in authorMutableArray) {
NSLog(@"String: %@", string);
}
NSLog(@"Init in Add Model with Author count:%i", [authorMutableArray count]);
}
}
访问属性的示例。 NSLog 始终显示计数为 0。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == [self.addModel.authorMutableArray count] - 1 ) {
NSLog(@"count of %i", [self.addModel.authorMutableArray count]);
return UITableViewCellEditingStyleInsert;
}
else {
return UITableViewCellEditingStyleDelete;
}
}
else {
return UITableViewCellEditingStyleNone;
}
}
我在 init 中创建的数组没有保持它的值超过这个方法。有什么理由吗? for 循环将显示数组中的两个对象。如果我在调用 init 方法后尝试询问此问题,则数组为空。
更新:感谢大家的时间和眼睛。我忘记在 init 方法中返回 self。
【问题讨论】:
-
如何声明 authormutablearray 属性
-
它是常规合成属性。
-
@WDyson Warren 的意思是,您使用什么说明符?
strong,weak,assign?另外,你之后如何访问数组?你能给我们看一下代码吗? -
我会更新OP,它很强大。
-
在您的
editingStyleForRowAtIndexPath方法中,检查addModel是否也不是零。
标签: objective-c ios xcode nsmutablearray