uitableview repoaddata 호출에서 exc_bad_access
-
20-09-2019 - |
문제
나는이 머리카락을이 머리 위로 끌어 당기는 시점에왔다. UitableView의 ReloadData를 호출 할 때 EXC_BAD_ACCESS를 계속받습니다. 여기에 당신을위한 토대를 마련하겠습니다.
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의 대의원 방법은 다음과 같습니다. NSLOG는이 방법의 첫 번째 줄이지만 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가 ReloadData 직전에 NSLOG를 통해 NIL이 아니 었는지 확인했습니다. 나는 여기서 작은 것을 놓치고 있어야한다는 것을 안다. 모든 제안은 대단히 감사 할 것입니다. 감사!
해결책
언제 콜 스택을 보여줄 수 있습니까? EXC_BAD_ACCESS
발생합니까?
btw,
NSUInteger index = [indexPath row];
보다 훨씬 더 읽기 쉽습니다
NSUInteger index = [indexPath indexAtPosition:1];
제휴하지 않습니다 StackOverflow