سؤال

ولقد وصلنا إلى نقطة سحب شعري أكثر من هذا واحد. وأظل الحصول على EXC_BAD_ACCESS عندما أسميه reloadData لUITableView. سوف تضع الأساس للكم هنا.

وMainViewController.h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

@class iPROSAppDelegate;

@interface MainViewController : UIViewController <UIScrollViewDelegate, UITableViewDelegate, UITableViewDataSource> {
 iPROSAppDelegate *parent;

 ...

 NSMutableArray *contentSeqList;
 UITableView *contentSeqTable;
}

@property (nonatomic, retain) IBOutlet iPROSAppDelegate *parent;
...
@property (nonatomic, retain) NSMutableArray *contentSeqList;
@property (nonatomic, retain) IBOutlet UITableView *contentSeqTable;
...
- (IBAction)changeMainView:(id)sender;

@end

وMainViewController.m

- (IBAction)changeMainView:(id)sender{
    //do logs to make sure we get here and grab an NSDictionary object from another class
 NSLog(@"got to a change of main view");
 NSDictionary *myContentSequences = [[parent csList] grabCSListandReturnJSON:[sender tag]];
 NSLog(@"got cs list for tag %@: %@", [sender currentTitle], myContentSequences);

    //set up table view
 contentSeqTable = [[UITableView alloc] initWithFrame:CGRectMake(40, 20, 240, 300) style:UITableViewStyleGrouped];
 contentSeqTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
 [contentSeqTable setDelegate:self];
 [contentSeqTable setDataSource:self];
 NSLog(@"delegate: %@, data source: %@", [contentSeqTable delegate], [contentSeqTable dataSource]);
 contentSeqList = [[NSMutableArray alloc] init];

    //populate nsmutablearray contentseqlist using the nsdictionary mycontentsequences
 for (id dashboard in [myContentSequences objectForKey:@"dashboards"]){
  if ([dashboard objectForKey:@"error"] == nil){
   for (id contentsequence in [dashboard objectForKey:@"contentSequences"]){
    [contentSeqList addObject:[contentsequence objectForKey:@"name"]];
    NSLog(@"added object to content sequence list: %@", [contentsequence objectForKey:@"name"]);
   }
  }
 }
 [contentSeqTable reloadData];
 ...
}

ويسمى changeMainView عند النقر على زر في شاشة العرض الرئيسية. وفيما يلي الطرق مندوب أيضا لUITableView. لاحظ أن NSLogs هي الخطوط الأولى في هذه الأساليب، ولكن يمكنني تظهر لا في السجل حدة قبل EXC_BAD_ACCESS.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
 NSLog(@"content seq list count: %@", [contentSeqList count]);
 return [contentSeqList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
 NSLog(@"setting up the cells");
 NSUInteger index = [indexPath indexAtPosition:1];

 NSString *myId = @"id";
 if (tableView.editing) myId = @"idE";

 UILabel *name;

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myId];

 if (cell == nil){
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 20)  reuseIdentifier:myId] autorelease];

  float width = 260;
  if (tableView.editing) width = 240;

  name = [[[UILabel alloc] initWithFrame:CGRectMake(45, 1, width, 53)] autorelease];
  [name setBackgroundColor:[UIColor clearColor]];
  [name setTextColor:[UIColor blackColor]];
  [name setFont:[UIFont fontWithName:@"Helvetica" size: 18]];
  [name setAdjustsFontSizeToFitWidth:YES];
  [name setMinimumFontSize:11];
  [name setNumberOfLines:2];

  name.tag = 1;

  [cell.contentView addSubview:name];

 }
 else{
  name = (UILabel *)[cell.contentView viewWithTag:1];
 }

 if ([tableView indexPathForSelectedRow]){
  if (indexPath == [tableView indexPathForSelectedRow]){  
   [name setTextColor:[UIColor whiteColor]];
  }
  else{
   [name setTextColor:[UIColor blackColor]];
  }
 }
 else{
  [name setTextColor:[UIColor blackColor]];
 }

 [name setText:[contentSeqList objectAtIndex:index]];

 return cell;
}

وطرق مندوب هي جزء من نفس الفئة، MainViewController. لقد راجعت أيضا أن UITableView لم يكن صفرا عبر NSLog الحق قبل reloadData. وأنا أعلم أنني يجب أن تكون في عداد المفقودين شيء صغير هنا. ان اي اقتراحات سيكون محل تقدير كبير. شكرا!

هل كانت مفيدة؟

المحلول

هل يمكن ان تظهر مكدس الاستدعاءات عندما يحدث EXC_BAD_ACCESS؟

وراجع للشغل،

NSUInteger index = [indexPath row];

وهو أكثر قابلية للقراءة الكثير من

NSUInteger index = [indexPath indexAtPosition:1];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top