将数组传递给uitableviewcell时出现NSInvalidArgumentException

时间:2014-11-04 17:32:26

标签: ios objective-c iphone uitableview

您好我将uitableview放入tableview单元格中遇到了麻烦。当我尝试将其放入tableviewcell

我为tableviewcell创建了一个新视图。我将uitableview放入单元格并为tableviewcell创建一个新类并填充它。但我总是在[cell setNewsList:newsList]中收到错误;线。

2014-11-04 19:20:15.881 Peşindeyiz[6272:317992] -[UITableViewCell setNewsList:]: unrecognized    selector sent to instance 0x78ec00f0
2014-11-04 19:20:15.884 Peşindeyiz[6272:317992] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell setNewsList:]: unrecognized selector sent to instance 0x78ec00f0'
*** First throw call stack:
(
0   CoreFoundation                      0x0097b946 __exceptionPreprocess + 182
1   libobjc.A.dylib                     0x00604a97 objc_exception_throw + 44
2   CoreFoundation                      0x009835c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277
3   CoreFoundation                      0x008cc3e7 ___forwarding___ + 1047
4   CoreFoundation                      0x008cbfae _CF_forwarding_prep_0 + 14
5   PesÃßindeyiz                        0x000d3f82 -[MainViewController tableView:cellForRowAtIndexPath:] + 370
6   UIKit                               0x012d41bc -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 473
7   UIKit                               0x012d429e -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 77
8   UIKit                               0x012ada6b -[UITableView _updateVisibleCellsNow:isRecursive:] + 3034
9   UIKit                               0x012c83d1 -[UITableView layoutSubviews] + 222
10  UIKit                               0x0123ddd1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608
11  libobjc.A.dylib                     0x0061a771 -[NSObject performSelector:withObject:] + 70
12  QuartzCore                          0x04fa328f -[CALayer layoutSublayers] + 152
13  QuartzCore                          0x04f97115 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 397
14  QuartzCore                          0x04f96f70 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
15  QuartzCore                          0x04ef53c6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284
16  QuartzCore                          0x04ef678c _ZN2CA11Transaction6commitEv + 392
17  QuartzCore                          0x04ef6e58 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
18  CoreFoundation                      0x0089e9de __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
19  CoreFoundation                      0x0089e920 __CFRunLoopDoObservers + 400
20  CoreFoundation                      0x0089435a __CFRunLoopRun + 1226
21  CoreFoundation                      0x00893bcb CFRunLoopRunSpecific + 443
22  CoreFoundation                      0x008939fb CFRunLoopRunInMode + 123
23  GraphicsServices                    0x04ad124f GSEventRunModal + 192
24  GraphicsServices                    0x04ad108c GSEventRun + 104
25  UIKit                               0x011b28b6 UIApplicationMain + 1526
26  PesÃßindeyiz                        0x000d42fd main + 141
27  libdyld.dylib                       0x02ef5ac9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

MainViewController.m:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"HorizontalCell";

HorizontalTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSArray *item = self.news[indexPath.section];
NSMutableArray *newsList = [item valueForKey:@"news"];
[cell setNewsList:newsList];
/*for(NSArray *news in newsList){
    [cell.imageView setImageWithURL:[NSURL URLWithString:[news valueForKey:@"resim"]]];
    cell.textLabel.text = [news valueForKey:@"baslik"];
}*/
return cell;
}

Horizo​​ntalTableCell.h:

#import <UIKit/UIKit.h>

@interface HorizontalTableCell : UITableViewCell

@property (nonatomic,strong) NSMutableArray *newsList;
@property (weak, nonatomic) IBOutlet UITableView *horizontalTableView;

@end

Horizo​​ntalTableView.m

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.newsList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"NewsCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}

cell.textLabel.text = [self.newsList[indexPath.row] valueForKey:@"baslik"];

return cell;
}

0 个答案:

没有答案