UITableView에 데이터를 표시하는 응용 프로그램이 있습니다. 그러나 하단 행을 표시하려고하면 충돌이 발생합니다. 희망이 누군가가 왜 이런 일이 일어나고 있는지 밝힐 수 있습니다.UITableView를 스크롤하여 하단 행을 표시 할 때 응용 프로그램이 충돌 함
-(void)viewDidLoad {
NSLog(@"myString is :%@", myString);
int processID = [myString intValue];
//NSLog(@"transferredArray is %@", transferredArray);
task = [[NSTask alloc] init];
[task setLaunchPath: @"/bin/ps"];
arguments = [NSArray arrayWithObjects: @"aux", [NSString stringWithFormat:@"%i", processID],nil];
[task setArguments: arguments];
NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput:pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
NSLog(@"ps aux output :%@",string);
NSArray *lines= [string componentsSeparatedByString:@"\n"];
NSString *lastline = [lines objectAtIndex:[lines count]-2];
// NSLog(@"%@",lastline);
lines2= [lastline componentsSeparatedByString:@" "];
NSLog(@"%@",lines2);
for (int i=0; i<[lines2 count]; i++) {
if([[lines2 objectAtIndex:i] isEqualToString:@""]){
[lines2 removeObjectAtIndex:i];
}
}
for (int i=0; i<[lines2 count]; i++) {
if([[lines2 objectAtIndex:i] isEqualToString:@""]){
[lines2 removeObjectAtIndex:i];
}
}
NSLog(@"lines2 after for loops is %@", lines2);
NSLog(@"Lines 2 is%@",lines2);
// NSLog(@"Status is %@",[lines2 objectAtIndex:7]);
self.title = @"Process Info";
label = [[NSMutableArray alloc]init];
[label addObject:@"User:"];
[label addObject:@"Process ID:"];
[label addObject:@"CPU(%):"];
[label addObject:@"MEM(%):"];
[label addObject:@"VSZ"];
[label addObject:@"RSS"];
[label addObject:@"TT"];
[label addObject:@"STAT:"];
[label addObject:@"Time Started:"];
[label addObject:@"Time Elapsed:"];
[label addObject:@"Command:"];
[super viewDidLoad];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UILabel *label2;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.textColor = [UIColor colorWithRed:154.0/255.0 green:14.0/255.0 blue:2.0/255.0 alpha:1];
cell.font = [UIFont systemFontOfSize:16.0];
label2 = [[[UILabel alloc] initWithFrame:CGRectMake(120.0, 0, 240.0,
tableView.rowHeight)]autorelease];
label2.font = [UIFont systemFontOfSize:16.0];
NSString *cellValue1 = [lines2 objectAtIndex:indexPath.row];
label2.text = cellValue1;
label2.textAlignment = UITextAlignmentLeft;
label2.textColor = [UIColor blackColor];
label2.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleHeight;
[cell.contentView addSubview:label2];
}
NSString *cellValue = [label objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell;
}
- (void)viewWillDisappear:(BOOL)animated
{
[task terminate];
[task release];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [lines2 count];
}
- (void)dealloc
{
//[transferredArray release];
//[myString release];
//[arguments release];
//[ResultStringID release];
//[values release];
//[label release];
[super dealloc];
}
참고 : 나는 모든 [출시]의 다른 EXEC_BAD_ACCESS 오류를 방지하기 위해 할당 해제의 방법에서, 나는 발생하고있는 현재의 에러가 EXEC_BAD_ACCESS가
에 액세스하기 위해 올 때 당신이 주변에하지 않을 수 있으므로 오토 릴리즈되어
cell.textLabel.text
lines2
를 설정 한 같은 장소의 내용을 변경해야합니다 메소드의 numberOfRowsInSection에서 cellForRowAtIndexPath에 레이블 배열을 사용 중입니다 .if lines2 이하의 레이블 개수가 충돌합니다. – Narayana