我正在尝试加载导航视图控制器,然后导致表格视图。表视图控制器使用标签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;
}
}
非常感谢你们!
答案 0 :(得分:0)
当您真正想要NSArray
实例时,似乎正在尝试使用NSString
实例。 UIKit尝试获取该“字符串”的长度(使用-length
消息)并且未能这样做,因为它不是字符串,而是数组。
答案 1 :(得分:0)
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;