试图显示多个标签从响应来自web服务ios



我试图在表视图(自定义表视图单元格复杂的设计)中显示web服务响应的驱动程序详细信息,但应用程序崩溃,我尝试了许多其他替代方案,但不工作,请帮助这里是代码:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{
    id jsonResponseData = [NSJSONSerialization JSONObjectWithData:self.responseData options:kNilOptions error:nil];
    NSArray * jsonResponseDataArray = [jsonResponseData objectForKey:@"data"];
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        [self createMarkerObjectsWithJson:jsonResponseDataArray];
    }];
    [[self driverListTableView] reloadData];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [arrayMain count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"Cell";
    //NSLog(@"arrayMain : %@",arrayMain);
    //method to return custom cell
    DriverListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"DriverListTableViewCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    //NSLog(@"nsarray: %lu",(unsigned long)[arrayMain count]);
    NSDictionary *testDict = [arrayMain objectAtIndex:indexPath.row];
    NSLog(@"mainDict : %@",testDict);
    NSString *firstName = [testDict objectForKey:@"f_name"];
    NSString *lastName = [testDict objectForKey:@"l_name"];
    NSString  *companyName = [NSString stringWithFormat:@"%@ %@",firstName,lastName];
    NSString *basePrice = [testDict objectForKey:@"base_price"];
    NSString *carType = [testDict objectForKey:@"car_type_label"];
    NSString *waitingTime = [testDict objectForKey:@"waiting_time"];
    NSLog(@"d_id %@",companyName);
    cell.labelCompanyName.text = companyName;
    //cell.imageView.image = [UIImage imageNamed:@"driver-1.png"];
    cell.labelBasePrice.text = basePrice;
    cell.labelCarType.text = carType;
    cell.labelWaitingTime.text = waitingTime;
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"selected at index: %ld",(long)indexPath.row);
}
@end

当我试图在cellForRowAtindexpath方法中显示多个标签时,应用程序崩溃了。如果你不能理解这个问题,请在评论中告诉我,我会提供更多的信息。

jsonResponseData是:

{
    count = 131;
    data =     (
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 1;
            "car_type_label" = "";
            color = "";
            "d_id" = bZ;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 8;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 2;
            "car_type_label" = "";
            color = "";
            "d_id" = KlCxEa;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 20;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = bZHXHX;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sourav;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 22;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlbZCx;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sourav;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 21;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlbZKl;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sourav;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 15;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlbZpS;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 22;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlpSQv;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 15;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlpSHX;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sudipta;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 7;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlEabZ;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 6;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlQvEa;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 14;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = KlHXmN;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Brando;
            status = 1;
            "waiting_time" = 8;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNbZCx;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Brando;
            status = 1;
            "waiting_time" = 6;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNbZEa;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 16;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNmNEa;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 23;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNmNbG;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sudipta;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 20;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNOrKl;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Brando;
            status = 1;
            "waiting_time" = 9;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNOrbG;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 22;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNEamN;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sudipta;
            "l_name" = Roy;
            status = 1;
            "waiting_time" = 28;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = mNEapS;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Singh;
            status = 1;
            "waiting_time" = 24;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrCxKl;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 30;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrCxmN;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Roy;
            status = 1;
            "waiting_time" = 7;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrmNbZ;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Roy;
            status = 1;
            "waiting_time" = 24;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrmNQv;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Vasu;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 19;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrOrCx;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 19;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrOrmN;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Saikat;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 22;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrEabZ;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Sourav;
            "l_name" = Khan;
            status = 1;
            "waiting_time" = 12;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrHXbZ;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Brando;
            status = 1;
            "waiting_time" = 25;
        },
                {
            "base_fare" = 20;
            "c_no" = "";
            "c_type" = 3;
            "car_type_label" = "";
            color = "";
            "d_id" = OrHXHX;
            "d_type" = 1;
            "driver_type_label" = "";
            "f_name" = Amar;
            "l_name" = Prasad;
            status = 1;
            "waiting_time" = 29;
        }
    );
}
误差

-[NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000083 2015-09-19 16:09:42.153 sRider[4995:102757] ***由于未捕获的异常而终止应用程序'NSInvalidArgumentException',原因:'-[__NSCFNumber length]:无法识别的选择器发送到实例0xb000000000000083'***第一个抛出调用栈:(0 CoreFoundation 0x00000001113a4c65 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x000000011103dbb7 objc_exception_throw + 45 2 CoreFoundation
0x00000001113ac0ad -[NSObject(NSObject) doesNotRecognizeSelector:] +205 3 CoreFoundation 0x000000011130213c__forwarding_
+ 988 4 CoreFoundation 0x0000000111301cd8 _CF_forwarding_prep_0 + 120 5 UIKit
0 x0000000111970a74 - [UILabel_textRectForBounds: limitedtonumberolines: inclingshadow:] + 65 6 UIKit 0x00000001119708cf -[UILabel . txttextRectForBounds: limitedtonumberolines:] + 76 7 UIKit
0x0000000111974379 -[UILabel _intrinsicSizeWithinSize:] + 170 8
UIKit 0x0000000111974459 -[UILabel[size] + 76 9 UIKit
0 x0000000111e12a0c - [UIView (UIConstraintBasedLayout)+ 33 10 UIKit 0x0000000111e127d0 -[UIView(UIConstraintBasedLayout)]+ 422 11 UIKit 0x0000000111e19bc5 -[UIView(AdditionalLayoutSupport)]updateConstraints] + 162 12 UIKit
0x00000001119742c4 -[UILabel updateconconstraints] + 274

我修复了这个错误,似乎我必须改变我从数组中获取的值为字符串,因为它是在NSNumber中出现的,所以我通过将标签文本设置为NSString将其更改为NSString -字符串格式如下:

cell.labelBasePrice.text = [NSString stringWithFormat:@"%@",[testDict objectForKey:@"base_fare"]];
    cell.labelCarType.text = [NSString stringWithFormat:@"%@",[testDict objectForKey:@"car_type_label"]];
    cell.labelWaitingTime.text = [NSString stringWithFormat:@"Waiting %@",[testDict objectForKey:@"waiting_time"]];

0x00000001113ac0ad -[NSObject(NSObject) doesNotRecognizeSelector:]

这行告诉我,你正在发送一个消息给一个对象,在它的头中没有一些方法。

-[NSCFNumber length]: unrecognized selector sent to instance 0xb000000000000083 2015-09-19 16:09:42.153 sRider[4995:102757] *由于未捕获异常'NSInvalidArgumentException',原因:'-[__NSCFNumber length]:**

这个特别地告诉我你正在发送一个length功能给一些NSNumber对象它不使用那个功能。

[__NSCFNumber length]:无法识别的选择器发送到实例0x6d21350

你必须检查你的代码,看看你是否把NSNumber误认为NSString。看一下你的JSON,看看你是否在你的自定义类中发送了任何代表JSON的属性作为NSNumber,它们应该是NSString,或者如果你错误地将length消息发送给NSNumber,而实际上你需要其他方法

最新更新