【问题标题】:TheOS iOS Programmatically UITableview Code Crashes while ScrollingTheOS iOS 以编程方式 UITableview 代码在滚动时崩溃
【发布时间】:2017-10-03 08:26:00
【问题描述】:

我使用 TheOS 来开发我的越狱应用程序。这是我以编程方式编写的表格视图代码,我几乎做了最简单的方法来实现表格视图方法。表格视图将正确显示默认表格数据,但当我滚动表格视图时应用程序会崩溃。我的错误日志没有显示任何明显的日志。 请帮帮我,我真的不知道滚动视图时它会立即崩溃的原因。

#import "DeviceInfoTableViewController.h"

@interface DeviceInfoTableViewController ()

@end

@implementation DeviceInfoTableViewController
{
    NSArray *tableData;
}

- (void)loadView {
    [super loadView];
    self.title = @"Table View Controller";
}

- (void)viewDidLoad {
    [super viewDidLoad];

    // Initialize table data
    tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"the tableData count: %ld", (unsigned long)tableData.count);
    return tableData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (!cell) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    NSString *str = tableData[indexPath.row];
    cell.textLabel.text = str;
    return cell;
}

#pragma mark - Table view delegate

// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

@end

我也去看了 ips 崩溃报告,但它没有显示任何有用的信息。

错误日志:

Oct  3 16:18:51: --- last message repeated 2 times ---
Oct  3 16:18:51 iPhone ReportCrash[3617]: MS:Notice: Injecting: (null) [ReportCrash] (1141.16)
Oct  3 16:18:51 iPhone ReportCrash[3617]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/0MobileGestaltFaker.dylib
Oct  3 16:18:51 iPhone ReportCrash[3617]: MS:Error: binary does not support this cpu type
Oct  3 16:18:51 iPhone ReportCrash[3617]: MS:Error: failure to check GoldPPServer.dylib
Oct  3 16:18:51 iPhone ReportCrash[3617]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/RocketBootstrap.dylib
Oct  3 16:18:51 iPhone ReportCrash[3617]: task_set_exception_ports(B07, 400, F03, 0, 0) failed with error (4: (os/kern) invalid argument)
Oct  3 16:18:51 iPhone ReportCrash[3617]: ReportCrash acting against PID 3614
Oct  3 16:18:51 iPhone ReportCrash[3617]: Formulating crash report for process testproject[3614]
Oct  3 16:18:51 iPhone com.apple.xpc.launchd[1] (UIKitApplication:com.zxx.testproject[0x6965][3614]): Service exited due to signal: Segmentation fault: 11
Oct  3 16:18:51 iPhone ReportCrash[3617]: Saved report to /Library/Logs/CrashReporter/testproject_2017-10-03-161851_iPhone.ips
Oct  3 16:18:51 iPhone SpringBoard[3524]: Application 'UIKitApplication:com.zxx.testproject[0x6965]' crashed.
Oct  3 16:18:51 iPhone assertiond[52]: pid_suspend failed for <BKNewProcess: 0x12fe2dfa0; com.zxx.testproject; pid: 3614; hostpid: -1>: Unknown error: -1, Unknown error: -1
Oct  3 16:18:51 iPhone assertiond[52]: Could not set priority of <BKNewProcess: 0x12fe2dfa0; com.zxx.testproject; pid: 3614; hostpid: -1> to 2, priority: No such process
Oct  3 16:18:51 iPhone assertiond[52]: Could not set priority of <BKNewProcess: 0x12fe2dfa0; com.zxx.testproject; pid: 3614; hostpid: -1> to 4096, priority: No such process
Oct  3 16:18:51 iPhone UserEventAgent[44]: id=com.zxx.testproject pid=3614, state=0
Oct  3 16:18:56 iPhone mstreamd[3606]: (Note ) mstreamd: Not monitoring for external power.
Oct  3 16:18:56 iPhone mstreamd[3606]: (Note ) PS: Media stream daemon stopping.
Oct  3 16:18:56 iPhone mstreamd[3606]: (Note ) AS: <MSIOSAlbumSharingDaemon: 0x145e74010>: Shared Streams daemon has shut down.
Oct  3 16:18:56 iPhone mstreamd[3606]: (Warn ) mstreamd: mstreamd shutting down.
Oct  3 16:18:56 iPhone mstreamd[3620]: MS:Notice: Injecting: com.apple.mediastream.mstreamd [mstreamd] (1141.16)
Oct  3 16:18:56 iPhone mstreamd[3620]: MS:Notice: Loading: /Library/MobileSubstrate/DynamicLibraries/0MobileGestaltFaker.dylib
Oct  3 16:18:56 iPhone mstreamd[3620]: MS:Error: binary does not support this cpu type
Oct  3 16:18:56 iPhone mstreamd[3620]: MS:Error: failure to check GoldPPServer.dylib
Oct  3 16:18:56 iPhone mstreamd[3620]: (Note ) mstreamd: mstreamd starting up.
Oct  3 16:18:56 iPhone mstreamd[3620]: (Note ) PS: Media stream daemon starting...
Oct  3 16:18:57 iPhone locationd[99]: Gesture EnabledForTopCLient: 0, EnabledInDaemonSettings: 0

我通过这种方式从另一个 Root 视图控制器调用这个 tableView:

- (void)deviceInfoTap:(id)sender {
    DeviceInfoTableViewController *controller = [[DeviceInfoTableViewController alloc] init];
    [self.navigationController pushViewController:controller animated:YES];
}

【问题讨论】:

  • 我认为你不需要在单元格上自动释放,单元格 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];删除它,然后重试。
  • 感谢您的快速回复,但我尝试了您的解决方案仍然崩溃...Orz,我们还有其他解决方案吗?
  • 你可以尝试注释掉 [tableView deselectRowAtIndexPath:indexPath animated:YES];看看它是否仍然崩溃
  • 你能从 Xcode 控制台发布日志吗
  • 我希望表格视图在任何弹出视图上并正确接收触摸动作。

标签: ios objective-c uitableview theos


【解决方案1】:

这可能是由于对您的 tableData 的弱引用而发生的。为您的 tableData 分配强参考:

@interface DeviceInfoTableViewController ()

@property (nonatomic, strong) NSArray *tableData;

@end

然后在viewDidLoad中:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Initialize table data
    _tableData = [NSArray arrayWithObjects:@"Egg Benedict", @"Mushroom Risotto", @"Full Breakfast", @"Hamburger", @"Ham and Egg Sandwich", @"Creme Brelee", @"White Chocolate Donut", @"Starbucks Coffee", @"Vegetable Curry", @"Instant Noodle with Egg", @"Noodle with BBQ Pork", @"Japanese Noodle with Pork", @"Green Tea", @"Thai Shrimp Cake", @"Angry Birds Cake", @"Ham and Cheese Panini", nil];
}

【讨论】:

  • 你好,我试试你的方法,但仍然崩溃....它也可以正常显示数据,但滚动时崩溃。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-07-10
  • 2011-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多