2011-09-07 70 views
0
我在与我的应用程序有问题

解析XML,我试图通过复制一个标签来保存核心数据的东西,但它给我这个错误帮助iOS中

终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [__ NSCFString appendString:]:无参数'

这是代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 


    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
    } 



    ClientDownload *currentClientDownload = [[xmlClientDownloadParser clientArray] objectAtIndex:indexPath.row]; 


    CGRect contentFrame = CGRectMake(45, 2, 265, 30); 
    clientName = [[[UILabel alloc] initWithFrame:contentFrame] autorelease]; 
    clientName.numberOfLines = 2; 
    clientName.font = [UIFont boldSystemFontOfSize:12]; 
    clientName.text = [currentClientDownload NAME]; 
    [cell.contentView addSubview:clientName]; 

    CGRect detailFrame1 = CGRectMake(45, 40, 265, 30); 
    clientMobile = [[[UILabel alloc] initWithFrame:detailFrame1] autorelease]; 

    CGRect detailFrame2 = CGRectMake(45, 40, 265, 30); 
    clientAccount = [[[UILabel alloc] initWithFrame:detailFrame2] autorelease]; 

    clientAccount.font = [UIFont systemFontOfSize:10]; 
    clientAccount.text = [currentClientDownload ACCOUNT]; 
    clientMobile.font = [UIFont systemFontOfSize:10]; 
    clientMobile.text = [currentClientDownload MOBILE]; 


    [cell.contentView addSubview:clientAccount]; 
    [cell.contentView addSubview:clientMobile]; 

    NSLog(@"SaveData"); 
    Clients *client = (Clients *)[NSEntityDescription insertNewObjectForEntityForName:@"Clients" inManagedObjectContext:managedObjectContext]; 
    if((clientName.text) || (clientAccount.text) || (clientMobile.text) != NULL) 
    { 
     client.ACCOUNT = clientAccount.text; 
     client.NAME = clientName.text; 
     client.MOBILE = clientMobile.text; 
     NSLog(@"CLIENT GENERATED"); 
     NSError *error; 

     if (![managedObjectContext save:&error]) 
     { 
      NSLog(@"Problem saving: %@", [error localizedDescription]); 
     } 

} 
    NSError * error; 
    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Clients" inManagedObjectContext:managedObjectContext]; 
    [fetchRequest setEntity:entity]; 
    NSArray *fetchedObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error]; 


    for (NSManagedObject *info in fetchedObjects) 

    { 

     NSLog(@"ACCOUNT: %@",[info valueForKey:@"ACCOUNT"]); 
     NSLog(@"NAME: %@",[info valueForKey:@"NAME"]); 
     NSLog(@"MOBILE: %@",[info valueForKey:@"MOBILE"]); 

    } 

    [fetchRequest release]; 
    return cell; 

} 
+0

代码崩溃的代码行。你有没有堆栈跟踪? – TechZen

回答

0

正如我看你有没有错的,如果语句的位置:

    if((clientName.text) || (clientAccount.text) || (clientMobile.text) != NULL)

看起来应该像这样的(如果我没有记错的话):

if((clientName.text != NULL) && (clientAccount.text != NULL) && (clientMobile.text != NULL))

+0

仍然给我的错误,我试图改变它一下,但由于某种原因,我即将开始等待围栏错误太... ....废话 –

+0

什么行失败?在我提出修改后,您是否删除了所有应用数据?你应该重置应用程序数据 – Nekto

+0

你想看看应用程序?即时尝试查看生成的数据在另一个视图....其实现在给我的围栏错误很多现在:/ –

0

在你的if语句,你正在检查所有三个UILabel S代表零文本在同时。这意味着,如果其中一个文本中有文本,而另外两个文本是空的,if条件将返回YES。然后尝试将此空文本分配给您的自定义对象。

您应该修改您的if语句以分别引用每个字段。因此:

if (clientAccount.text != nil) client.ACCOUNT = clientAccount.text; 
if (clientName.text != nil)  client.NAME = clientName.text; 
if (clientMobile.text != nil) client.MOBILE = clientMobile.text; 

如果这样不能解决问题,请发布确切的线路,让您知道崩溃的位置。

+0

与您的修复,代码甚至不通过XML解析加载数据!如果你想看看代码,我会很高兴向你发送代码,它很难粘贴6个类:/ –

+0

好吧,它似乎是在你的问题所在的地方...尝试设置将属性设置为@“”而不是将它们留在'nil'。 – Mundi

+0

另外,我不会导入新记录并将它们保存在'cellForRowAtIndexPath:'中。这种方法有可能被多次调用。也许这是你遇到麻烦的地方。 – Mundi