我有下面的代码来填充一个通知数组。这个数组需要用来填充我的iOS应用程序中的一个菜单,其中包含通知。
// extract specific value...
NSArray *switchValues = [res objectForKey:@"data"];
NSLog(@"%@", switchValues);
for (NSDictionary *switchValue in switchValues) {
NSString *text = [switchValue objectForKey:@"text"];
NSLog(@"%@", text);
[self.notificationsArray addObject:text];
}再往下走,我会这样做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSMutableArray *titles = self.notificationsArray;
cell.textLabel.text = titles[indexPath.row];
return cell;
}但是,我总是得到一个空数组。我做错了什么?
发布于 2014-11-25 23:36:40
你为什么不这么做呢
[notificationsArray objectAtIndex:indexPath.row]而不是
NSMutableArray *titles = self.notificationsArray; cell.textLabel.text = titles[indexPath.row];?
如果你真的不想要,至少可以使用NSMutableArray *titles = [NSMutableArray arrayWithArray:self.notificationsArray];
在第一段代码中,控制台日志是什么?你确定你在for循环中输入了吗?
https://stackoverflow.com/questions/27130371
复制相似问题