2011-08-15 4 views
-4

그룹화 된 단면 뷰를 작성하려고합니다. 사전에 객체를 배열로 설정하려고하지만 빈 배열 문제를 발견했습니다. 이게 가능합니까 ????? There is a trick ???NSString을 사용하여 NSArray를 구현할 수 있습니까?

#import "RootViewController.h" 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    // Get the specific Node for this row. 
    Nodes *nodes = (Nodes *)[nodesMArray objectAtIndex:indexPath.row]; 
    // Create the Details View Controller and initialize it. 
    nodesDetailView *viewController = [[nodesDetailView alloc] initWithStyle:UITableViewStyleGrouped ]; 
    [[self navigationController] pushViewController:viewController animated:YES]; 

    // Set the title of the view to the nodes name 
    viewController.title = [nodes computer_name]; 
    //Information 
    //Network Data 
    viewController.ipaddress= [nodes ipaddress]; 
    viewController.subnet_mask= [nodes subnet_mask]; 
    viewController.gateway= [nodes gateway]; 
    viewController.domain_name= [nodes domain_name]; 
} 

#import "nodesDetailViewController. h 


@interface nodesDetailView : UITableViewController{ 

//Network Data 
NSString *ipaddress; 
NSString *subnet_mask; 
NSString *gateway; 
NSString *domain_name; 

//Grouped 
NSMutableArray *Keys; 
NSMutableDictionary *Contents; 

} 

@property (nonatomic, retain) NSMutableArray *Keys; 
@property (nonatomic, retain) NSMutableDictionary *Contents; 



@property (nonatomic, retain) NSString *ipaddress; 
@property (nonatomic, retain) NSString *subnet_mask; 
@property (nonatomic, retain) NSString *gateway; 
@property (nonatomic, retain) NSString *domain_name; 



@end 

#import "nodesDetailViewController. m 


@synthesize ....... 


- (id)initWithStyle:(UITableViewStyle)style 
{ 
self = [super initWithStyle:style]; 
if (self) { 

    NSMutableArray *keys = [[NSMutableArray alloc] init]; 
    NSMutableDictionary *contents = [[NSMutableDictionary alloc] init]; 


    NSString *network = @"Network Data"; 
    NSString *product = @"Product Details"; 

    //IS THIS POSSIBLE ??????? Because I get An Empty array 
    [contents setObject:[NSArray arrayWithObjects: ipaddress,subnet_mask, gateway, domain_name, nil] forKey:network]; 

return self; 
} 

감사합니다.

+0

어떻게 비어 있다는 것을 알고 계십니까? –

+0

귀하의 질문을 명확하게하십시오 ... –

+0

NSlog it and arry 내용은 { "일반 정보"= ( )입니다. "네트워크 데이터"= ( ); "제품 세부 정보"= ( ); } – ngeran

답변

0

궁금한 분 : 문제가 해결되었습니다. 코드가 괜찮습니다. 문제는 : 잘못된 위치에있었습니다.

강령은에 있어야 - (무효) viewDidLoad에하지에 - (ID) initWithStyle :

나는 그것을에 볼 수있는 시간이 걸렸습니다 모두에게 감사드립니다. 나는 왜 코드를 거기에 넣을지 모르겠다.

고맙습니다

0

배열에 추가하는 모든 문자열은 아직 할당/초기화되지 않았습니다. 이것이 배열이 비어있는 이유입니다. 너는 갈 수 없어 : NSString *emptyString; 그리고 가서 : [myArray addObject:emptyString];. 당신의 현은 모두 비어 있습니다.

+0

그래도 여전히 작동하지 않습니다. – ngeran

0

u가 통과하는 값을 테이블보기에서 확인하십시오. 아마도 그럴 수 없습니다. 방금이 많은 데이터를 사용했고 올바른 NSLog를 얻었습니다.

NSMutableDictionary *contents = [[NSMutableDictionary alloc] init]; 
NSString *my = @"kk"; 
NSString *my1 = @"polko"; 
[contents setObject:[NSArray arrayWithObjects: my1,my, nil] forKey:@"o"]; 
NSLog(@"%@" , contents); 
+0

나는 이미 그렇게했고 그것은 작동합니다. 문제는 viewController.ipaddress = [nodes ipaddress]와 함께 작동하지 않는다는 것입니다. 배열 안의 ipaddress는 아무것도주지 않습니다. 그러나 내가 UILabel을 만들고 headerLabel.text = ipaddress와 같은 것을하면; 잘 작동 왜 배열 내에서 작동하지 ??? – ngeran

+0

[nodes ipaddress]를 (를) nil ..으로 사용하고 있습니까? NSLog에이 성명서를 제출하십시오. – Hadi

관련 문제