目标C错误-[__ NSArrayI长度]:无法识别

尼古拉斯

我正在尝试加载一个导航视图控制器,该控制器然后导致一个表视图。表格视图控制器使用标签textview和另一个标签从Parse Cloud收集信息。所有这些代码都可以在我制作的源代码中使用,但现在无法弄清楚。这是我收到的错误消息:

2014-07-28 00:15:13.922 Screamery[7882:1236765] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <AllDataViewController: 0x14f6088e0>.  Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior.  This method will no longer be called in a future release.
    2014-07-28 00:15:15.323 Screamery[7882:1236765] -[__NSArrayI length]: unrecognized selector sent to instance 0x178225b40
    2014-07-28 00:15:15.323 Screamery[7882:1236765] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x178225b40'
    *** First throw call stack:
    (0x181eccbe4 0x19190c1ac 0x181ed3bf4 0x181ed09a8 0x181dd659c 0x182d046b8 0x186547f90 0x1000ba578 0x100103ed4 0x186792400 0x1867871fc 0x186570560 0x186570418 0x100102ea0 0x1000ba914 0x100103504 0x100123be0 0x100371a3c 0x1003719fc 0x1003758c8 0x181e84688 0x181e82730 0x181db0bd4 0x18acf360c 0x186502a0c 0x1000bda28 0x191f82a08)
    libc++abi.dylib: terminating with uncaught exception of type NSException

这是我的AllDataViewController:

- (id)initWithCoder:(NSCoder *)aCoder
{
    self = [super initWithCoder:aCoder];
    if (self) {
        // Custom the table

        // The className to query on
        self.parseClassName = @"Reviews";

        // The key of the PFObject to display in the label of the default cell style
        self.textKey = @"name";

        // Whether the built-in pull-to-refresh is enabled
        self.pullToRefreshEnabled = YES;

        // Whether the built-in pagination is enabled
        self.paginationEnabled = NO;

        // The number of objects to show per page
        //self.objectsPerPage = 10;
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(refreshTable:)
                                                 name:@"refreshTable"
                                               object:nil];
}

- (void)refreshTable:(NSNotification *) notification
{
    // Reload the data
    [self loadObjects];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"refreshTable" object:nil];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (PFQuery *)queryForTable
{
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

    // If no objects are loaded in memory, we look to the cache first to fill the table
    // and then subsequently do a query against the network.
    /*    if ([self.objects count] == 0) {
     query.cachePolicy = kPFCachePolicyCacheThenNetwork;
     }*/

    //    [query orderByAscending:@"name"];

    return query;
}

-(UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath: (NSIndexPath *)indexPath {

    return UITableViewCellAccessoryNone;
}



// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
    static NSString *simpleTableIdentifier = @"DataCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        //        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];

        cell.accessoryType = UITableViewCellAccessoryNone;

    }



    // Configure the cell


    UILabel *nameLabel = (UILabel*) [cell viewWithTag:101];
    nameLabel.text = [object objectForKey:@"name"];

    UILabel *priceLabel = (UILabel*) [cell viewWithTag:102];
    priceLabel.text = [object objectForKey:@"price"];

    UITextView *informaationLabel = (UITextView *) [cell viewWithTag:103];
    informaationLabel.text = [object objectForKey:@"information"];

    return cell;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Remove the row from data model
    PFObject *object = [self.objects objectAtIndex:indexPath.row];
    [object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        [self refreshTable:nil];
    }];
}

- (void) objectsDidLoad:(NSError *)error
{
    [super objectsDidLoad:error];

    NSLog(@"error: %@", [error localizedDescription]);
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showDataDetail"]) { //showRecipeDetail
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        DataDetailViewController *destViewController = segue.destinationViewController;

        PFObject *object = [self.objects objectAtIndex:indexPath.row];
        AllData *data = [[AllData alloc] init];
        data.name = [object objectForKey:@"name"];
        data.price = [object objectForKey:@"price"];
        data.information = [object objectForKey:@"information"];
        destViewController.data = data;

    }
}

非常感谢大家!

拉杰什

length()NSString的实例方法因此,崩溃应该发生在下面几行

nameLabel.text = [object objectForKey:@"name"];

priceLabel.text = [object objectForKey:@"price"];

informaationLabel.text = [object objectForKey:@"information"];

检查这些对象中是否有任何一个保存数组引用。

更加清晰

 NSMutableString ingredientText = [NSMutableString string]; 
for (NSString ingredient in _data.information) 
{ 
[ingredientText appendFormat:@"%@\n", ingredient]; 
} 
self.informationTextView.text = ingredientText;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章