我是iOS开发人员的新手。我正在制作一个应用程序,我正在收到JSON的回复。但当我点击按钮显示下一个UITableView。 我对每个人都有两个问题。
1.)之前会显示空值。我必须向下滚动显示值。
2.)向下滚动调试错误后显示"由于未捕获的异常终止应用程序' NSRangeException',原因:' - [__ NSCFArray objectAtIndex:]:index(14)超出界限(14)"
抱歉我的英语不好。我会说一点英语。
我们必须单击按钮才能转到下一个UITableView。
- (IBAction)btnf10
{
NSMutableDictionary *content = [NSMutableDictionary dictionary];
[content setValue:[[AppSetting sharedInstance] token] forKey:@"ewitoken"];
//[content setValue:gloablOnWherehouse.selectedWhereHouse forKey:@"model_Name"];
[[EWIConnector connector] requestEWIService:@"special_selected_f10" requestData:content delegate:self];
}
requestEWIServiceStart将检查String。
- (void) requestEWIServiceStart:(EWIConnector *)connector{
NSLog(@"start %@",connector.endpoint);
}
- (void) requestEWIServiceFinish:(EWIConnector *)connector responseData:(NSDictionary *)responseData{
NSLog(@"finish %@",connector.serviceName);
NSLog(@"response %@",responseData);
if ([connector.serviceName isEqualToString:@"special_selected_f10"])
{
NSLog(@"finish %@",connector.serviceName);
NSDictionary *content = responseData[@"content"];
NSString *stAlertMes = [content objectForKey:@"alertMessage"];
stAlertMes = [self getString:stAlertMes];
NSLog(@"AlertMSG : %@", stAlertMes);
if (![stAlertMes isEqualToString:@""]) {
NSLog(@"ALERT MESSAGE : %@", stAlertMes);
gloablOnWherehouse.arTableDataSelected = [[NSArray alloc] init];
}
else
{
NSLog(@"HAS DATA");
gloablOnWherehouse.arTableDataSelected = [content objectForKey:@"DataList_SPI_DetailCollection"];
[self.tableViewWhereHoseList reloadData];
labelStatus.text = @"F11";
}
}
else
{
NSLog(@"response %@",responseData);
}
}
UITableView 2用于响应数据。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
globlOnDisplayEffect = [GlobalVariable sharedInstance];
globlOnDisplayEffect.arTableDataSelectedWhereHouse = [[NSArray alloc] init];
[self.tableViewDetailList reloadData];
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return (globlOnDisplayEffect.arTableDataSelected)?[globlOnDisplayEffect.arTableDataSelected count]: 100;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"DisplayEffectQtyViewCell";
DisplayEffectQtyViewCell *cell = [self.tableViewDetailList dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DisplayEffectQtyViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
} else {
if (globlOnDisplayEffect.arTableDataSelected) {
NSMutableArray *myMutbleArray = [[NSMutableArray alloc] init];
[myMutbleArray addObject:globlOnDisplayEffect.arTableDataSelected];
if (myMutbleArray) {
NSDictionary *myDic = [globlOnDisplayEffect.arTableDataSelected objectAtIndex:indexPath.row];
NSDictionary *cont = [myDic objectForKey:@"DataList_SPI_DetailF10"];
NSString *f10_cmpt = [self getString:[cont objectForKey:@"f10_cmpt"]];
NSString *f10_dt = [self getString:[cont objectForKey:@"f10_dt"]];
NSString *f10_item = [self getString:[cont objectForKey:@"f10_item"]];
NSString *f10_lot = [self getString:[cont objectForKey:@"f10_lot"]];
NSString *f10_model = [self getString:[cont objectForKey:@"f10_model"]];
NSString *f10_of = [self getString:[cont objectForKey:@"f10_of"]];
NSString *f10_semi = [self getString:[cont objectForKey:@"f10_semi"]];
NSString *f10_tm = [self getString:[cont objectForKey:@"f10_tm"]];
NSString *f10_uncmp = [self getString:[cont objectForKey:@"f10_uncmp"]];
[cell setf10_cmpt:f10_cmpt setf10_dt:f10_dt setf10_item:f10_item setf10_lot:f10_lot setf10_model:f10_model setf10_of:f10_of setf10_semi:f10_semi setf10_tm:f10_tm setf10_uncmp:f10_uncmp];
}
}
}
return cell;
}
答案 0 :(得分:0)
数组的索引绑定,这是一个常见问题。数组中第14个位置没有对象。
在加载tableview之前,使用控制台中的循环NSLog所有数据,你必须在Cell中显示。
else
{
NSLog(@"HAS DATA");
gloablOnWherehouse.arTableDataSelected = [content objectForKey:@"DataList_SPI_DetailCollection"];
// [self.tableViewWhereHoseList reloadData];
labelStatus.text = @"F11";
}
并检查您要加载的表格视图并将其计算在内。我想,应该是
[globlOnDisplayEffect.arTableDataSelected count]>0 ?[globlOnDisplayEffect.arTableDataSelected count]:100.
解释,为什么在[globlOnDisplayEffect.arTableDataSelected count] == 0时会显示100个单元格。其他的数据来源是什么?
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// NSLog what you return....
return (globlOnDisplayEffect.arTableDataSelected)?[globlOnDisplayEffect.arTableDataSelected count]: 100;
}
检查表格单元格条件。 **