【问题标题】:Application Terminates Without Error应用程序终止而没有错误
【发布时间】:2011-12-26 08:46:22
【问题描述】:

成功切换到视图后,我的应用程序在模拟器中终止。我确信这很简单,这是终止应用程序的视图中的 .m 文件。也许有些东西没有释放。它不会在控制台中抛出错误,页面加载,等待几秒钟,然后终止并在调试器中抛出 mach_msg_trap。如果我点击播放按钮,它将继续。

  @implementation ProspectViewController

@synthesize jsonArray;

- (void)viewDidLoad {
[super viewDidLoad];
NSURL *jsonURL = [NSURLURLWithString:@"https://www.mysite.php"];

NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];


self.jsonArray = [jsonData JSONValue]; 


[jsonURL release];
[jsonData release];
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}


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


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *infoDictionary = [self.jsonArray objectAtIndex:indexPath.row];
static NSString *Prospects = @"agencyname";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Prospects];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Prospects] autorelease];
}

// setting the text
cell.text = [infoDictionary objectForKey:@"agencyname"];    
self.navigationItem.title = @"Prospects";

// Set up the cell
return cell;

}

【问题讨论】:

  • ir 应该是由于这些陈述中的一个(或两个)[agencyName release]; [lblText 发布];
  • 放置 [super viewDidLoad];在方法的开头。
  • 在开头放置一个超级 viewDidLoad 没有帮助。它在 ret 下的调试器中抛出了一个 mach msg 陷阱。

标签: objective-c cocoa-touch ios4 iphone-sdk-3.0


【解决方案1】:

viewDidLoad中不要释放jsonurl,因为之前没有保留。只有类 init 的方法会保留实例,而不是静态构造函数。

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    • 1970-01-01
    • 2011-01-12
    • 1970-01-01
    • 2015-07-10
    相关资源
    最近更新 更多