如何将 1 和变化的数字之间的每个数字添加到 NSMutableArray(以便它可以显示在 UITableView 中)?
例如,如果此刻变化的数字是 8,那么数组应该包含:1, 2, 3, 4, 5, 6, 7, 8
。谢谢。
如何将 1 和变化的数字之间的每个数字添加到 NSMutableArray(以便它可以显示在 UITableView 中)?
例如,如果此刻变化的数字是 8,那么数组应该包含:1, 2, 3, 4, 5, 6, 7, 8
。谢谢。
我推荐以下方法(不需要数组)。为你的数字
-numberOfSectionsInTableView..{
return 1;
}
-numberOfRowsInSection..{
return a;
}
-cellForRowAtIndexPath..{
UITableViewCell* cell = ...
UILabel *label = ...
[label setText:[NSString stringWithFormat:@"%d",indexPath.row+1]];
[cell addSubView:label];
return cell;
}
生成一个包含 1 个部分、一个行的表,并且每行将有一个标签,其上带有数字 1 到 a。
塞巴斯蒂安
就像是:
int number = 8;
NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:number];
for (int i=1; i<=number; i++) {
[mutableArray addObject:[NSString stringWithFormat:@"%i", i]]
}
NSLog(@"%@", [mutableArray description]);
- (NSMutableArray*)arrayForNumber:(int)number {
NSMutableArray* array = [NSMutableArray array];
for (int i = 1; i <= number; i++) {
[array addObject:[NSNumber numberWithInt:i]];
}
return array;
}