我似乎无法弄清楚为什么我的应用程序在向我的表中添加对象时崩溃了。我使用这个 (http://www.theappcodeblog.com/2011/05/09/parsing-xml-in-an-iphone-app-tutorial/) 教程来解析 XML,它做得很好,但没有将我解析的 XML 中的数据添加到 UITableView。
这是我正在使用的代码:
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath
{
NSLog(@"starting table");
static NSString *cellid = @"Cell";
row *curname = [[xpar worker] objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellid]autorelease];
}
picframe = CGRectMake(0, 0, 100, 100);
UIImageView *imgview = [[UIImageView alloc]initWithFrame:picframe];
imgview.image = [UIImage imageNamed:[NSString stringWithFormat"%@", curname.pic]];
[cell.contentView addSubview:imgview];
nameframe = CGRectMake(105, 50, 50, 20);
namecon = [[UILabel alloc] initWithFrame:nameframe];
namecon.tag = 0011;
namecon.numberOfLines = 1;
namecon.font = [UIFont boldSystemFontOfSize:12.0];
[cell.contentView addSubview:namecon];
jobframe = CGRectMake(165, 75, 50, 20);
jobcon = [[UILabel alloc] initWithFrame:jobframe];
jobcon.tag = 0012;
jobcon.numberOfLines = 1;
jobcon.font = [UIFont systemFontOfSize:12.0];
[cell.contentView addSubview:jobcon];
majframe = CGRectMake(165, 25, 50, 20);
majcon = [[UILabel alloc] initWithFrame:majframe];
majcon.tag = 0013;
majcon.numberOfLines = 1;
majcon.font = [UIFont systemFontOfSize:12.0];
[cell.contentView addSubview:majcon];
namecon = (UILabel*)[cell.contentView viewWithTag:0011];
namecon.text = [curname name];
NSLog(@"%@", namecon.text);
jobcon = (UILabel*)[cell.contentView viewWithTag:0012];
jobcon.text = [curname job];
majcon = (UILabel*)[cell.contentView viewWithTag:0013];
majcon.text = [curname major];
return cell;
}
我正在使用带有 UITableView 的 Storyboard 和带有标识符“Cell”的 TableViewCell,就像代码中一样。 UIViewController的类就是上面代码的.m文件,UITableView使用的是Dynamic Prototypes,UITableView的dataSource和Delegate Outlets就是上面代码的.m文件,.m文件的Outlet链接到UITableView。
我对 Objective-C 和 iOS 开发人员也很陌生,所以如果这是一个非常明显的答案,我很抱歉。我尝试了很多不同的东西都无济于事。如果我的代码有任何其他部分我应该发布,我会尽快发布。
谢谢!
编辑:
崩溃后的日志:
2014-04-07 13:18:17.383 LabWorker[80097:60b] -[workersViewController
tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x10c3d4a60
2014-04-07 13:18:17.386 LabWorker[80097:60b] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[workersViewController
tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x10c3d4a60'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101acd495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010182c99e objc_exception_throw + 43
2 CoreFoundation 0x0000000101b5e65d -[NSObject(NSObject)
doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000101abeb85 ___forwarding___ + 453
4 CoreFoundation 0x0000000101abe938 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001005eba30 -[UISectionRowData
heightForRow:inSection:canGuess:] + 234
6 UIKit 0x00000001005f2334 -[UITableViewRowData
rectForRow:inSection:heightCanBeGuessed:] + 582
7 UIKit 0x00000001005f2432 -[UITableViewRowData
rectForGlobalRow:heightCanBeGuessed:] + 150
8 UIKit 0x00000001005f2dd5 -[UITableViewRowData
globalRowsInRect:canGuess:] + 359
9 UIKit 0x0000000100494531 -[UITableView
_visibleGlobalRowsInRect:] + 210
10 UIKit 0x00000001004937ab -[UITableView
_updateVisibleCellsNow:] + 881
11 UIKit 0x00000001004a5721 -[UITableView layoutSubviews] +
207
12 UIKit 0x0000000100439993 -[UIView(CALayerDelegate)
layoutSublayersOfLayer:] + 354
13 QuartzCore 0x000000010242a802 -[CALayer layoutSublayers] + 151
14 QuartzCore 0x000000010241f369
_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
15 QuartzCore 0x000000010241f1ea
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x0000000102392fb8
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
17 QuartzCore 0x0000000102394030 _ZN2CA11Transaction6commitEv +
394
18 QuartzCore 0x000000010239469d
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
19 CoreFoundation 0x0000000101a98dc7
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
20 CoreFoundation 0x0000000101a98d37 __CFRunLoopDoObservers + 391
21 CoreFoundation 0x0000000101a78522 __CFRunLoopRun + 946
22 CoreFoundation 0x0000000101a77d83 CFRunLoopRunSpecific + 467
23 GraphicsServices 0x0000000102f79f04 GSEventRunModal + 161
24 UIKit 0x00000001003d9e33 UIApplicationMain + 1010
25 LabWorker 0x0000000100002fa7 main + 103
26 libdyld.dylib 0x00000001068985fd start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
编辑:
更多代码/解释:
-(NSInteger)numberOfSectionsInTableViewUITableView *)tableView
{
NSLog(@"sections");
return 1;
}
-(NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section
{
NSLog(@"rows, %lu", (unsigned long)[[xpar worker] count]);
return [[xpar worker] count];
}
-(CGFloat)tableViewUITableView *)tableView estimatedHeightForRowAtIndexPathNSIndexPath *)indexPath
{
NSLog(@"CGFloat");
return 100;
}
它运行并获取 11 行的 [[xpar worker] 计数](正确的数字),然后运行“CGFloat”方法 11 次,然后它准确地显示了我在上面发布的日志显示的内容。
编辑:崩溃的地方:
#import <UIKit/UIKit.h>
#import "labAppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
---> return UIApplicationMain(argc, argv, nil, NSStringFromClass([labAppDelegate class]));
}
}
它说它在 main.m 文件中它上面的箭头处崩溃。
argc = 1
**argv = (char) '/'
Best Answer-推荐答案 strong>
您的日志说它需要 tableView:heightForRowAtIndexPath 方法
只需按如下方式实现此方法
- (CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath {
return 100;
}
关于ios - 尝试从 NSMutableArray 填充 UITableView 时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/22907388/
|