我有一个tableView,它以两个空数组开始(storageData& descripData - 因为用户尚未添加任何项目)。现在当我的用户添加一个项目(标题,描述和照片)并刷新tableView时,我收到错误:
' - [__ NSCFArray objectAtIndex:]:index(1)超出bounds(1)'
那就是说,我不确定为什么。见下面的代码;谢谢!
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([self.storageData count] > 0 && self.descripData.count > 0)
{
return [self.storageData count];
}
else
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *DoctorsTableIdentifier = @"StorageItemTableViewCell";
StorageItemTableViewCell *cell = (StorageItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:DoctorsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StorageItemTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (self.storageData.count > 0 && self.descripData.count > 0) {
noitemsView.hidden = YES;
NSDictionary *tmp = [self.storageData objectForKey:[NSString stringWithFormat:@"%d",(long)indexPath.row]];
[[cell itemName] setText:(NSString *)[tmp objectForKey:@"title"]];
NSString *title = [tmp objectForKey:@"title"];
[[cell itemName] setText:title];
NSDictionary *node = [self.descripData objectAtIndex:indexPath.row];
[[cell itemDescrip] setText:[node objectForKey:@"body"]];
NSLog(@"%@", self.descripData);
NSString *secondLink = [[self.descripData objectAtIndex:indexPath.row] objectForKey:@"photo"];
[cell.itemPhoto sd_setImageWithURL:[NSURL URLWithString:secondLink]];
NSLog(@"%@",secondLink);
}
else {
noitemsView.hidden = NO;
}
return cell;
}
答案 0 :(得分:1)
仔细观察self.descripData.count,因为在numberOrRowsInSection中你返回了[self.storageData count]。但似乎是self.storageData.count> self.descripData.count,因此您尝试获取self.descripData bounds之外的对象。这么简单。
答案 1 :(得分:0)
在storageData
方法中,如果storageData.count > 0
和descripData.count > 0
,则会返回NSDictionary *node = [self.descripData objectAtIndex:indexPath.row];
的计数。
正如你所说,它在self.storageData.count > self.descripData.count
似乎2015-05-14 13:48:06,192 INFO regionserver.StoreFile (StoreFile.java:close(1334)) - NO General Bloom and NO DeleteFamily was added to HFile (hdfs://localhost:8020/hbase/sometable/8854a960778fe379d454a79e27b653a1/.tmp/dea0e9ac00be44a1a3acba3b900bdf54)
2015-05-14 13:48:06,192 INFO regionserver.Store (Store.java:internalFlushCache(921)) - Flushed , sequenceid=4460077, memsize=128.0m, into tmp file hdfs://localhost:8020/hbase/sometable/8854a960778fe379d454a79e27b653a1/.tmp/dea0e9ac00be44a1a3acba3b900bdf54
2015-05-14 13:48:06,232 INFO regionserver.Store (Store.java:commitFile(968)) - Added hdfs://localhost:8020/hbase/sometable/8854a960778fe379d454a79e27b653a1/r/dea0e9ac00be44a1a3acba3b900bdf54, entries=742515, sequenceid=4460077, filesize=36.8m
2015-05-14 13:48:06,233 INFO regionserver.HRegion (HRegion.java:internalFlushcache(1776)) - Finished memstore flush of ~128.0m/134226872, currentsize=428.4k/438664 for region sometable,,1431608601110.8854a960778fe379d454a79e27b653a1. in 3043ms, sequenceid=4460077, compaction requested=false
。请检查两个数组的计数是否相同。