2011-08-24 70 views
1

我試圖使用UITableView列出特定進程的詳細信息。它在Xcode模擬器上運行時完美顯示。但是,在實際設備上部署時,它的格式不正確。令人費解的是,當我在Mac和iPhone上執行「ps aux」命令時,輸出的格式似乎是相同的。當在iPhone上部署「ps aux」命令輸出時格式不正確

這是怎麼看起來像在模擬器:

enter image description here

這是怎麼看起來像在實際設備上:

enter image description here

這裏是我的控制器代碼顯示這些視圖:

viewDidLoad:

NSLog(@"myString is :%@", myString); 
int processID = [myString intValue]; 

NSTask *task; 
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]; 
[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(@"%@",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(@"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:@"Launch Command:"]; 

[super viewDidLoad]; 

的cellForRowAtIndexPath:

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

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

[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
NSString *cellValue = [label objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 
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]; 


UILabel *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]; 


return cell; 

numberOfRowsInSection:

return [label count]; 

的dealloc:

[myString release]; 
[arguments release]; 
//[lines2 release]; 
[ResultStringID release]; 
[values release]; 
[label release]; 
[super dealloc]; 

的 「PS AUX」 命令在Mac輸出:

enter image description here

「的ps aux」 命令對iPhone的輸出(通過SSH殼):

enter image description here

+0

有點多餘的內容,首先在兩個平臺上發佈'ps aux'的輸出。 –

回答

0

有沒有保證ps iOS上做同樣的事情在其他平臺上。沒有用戶界面可以讓用戶訪問iOS設備上的ps命令,所以你很幸運有一個ps命令。嘗試從命令中記錄輸出以查看您獲得的內容,但如果沒有太多內容,請不要感到驚訝。

+0

是有輸出,但與Mac上相比,它的數據嚴重不足。還是要謝謝你的幫助 :) –