2011-08-15 218 views
-4

我正在尝试构建分组分段视图。我想设置一个数组作为字典中的对象,但我遇到了空数组问题。 这是甚至可能?????有一个诡计吗?NSArray与NSString这甚至可能吗?

#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它和我得到arry的内容是{ “一般信息”=( ); “网络数据”=( ); “产品详细信息”=( ); } – ngeran

回答

0

对于那些想知道的人:问题解决我的代码很好。问题是: 它是在错误的地方。

的代码应该是在 - (无效)viewDidLoad中,而不是在 - (ID)initWithStyle:

我要感谢大家谁花时间在看它。 我不知道为什么我把代码放在那里开始。

Thanx Again

0

所有你添加到数组的字符串还没有被分配/初始化。这就是数组为空的原因。你不能只是去:NSString *emptyString;然后去:[myArray addObject:emptyString];。你的字符串都是空的。

+0

即使我这样做仍然不起作用。 – ngeran

0

检查您从表格视图中传递的值。他们可能是零。我只是使用了这么多的数据,我得到了正确的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 = [节点ipaddress];数组内的ipaddress不给我任何东西。但是,如果我创建一个UILabel并执行诸如headerLabel.text = ipaddress;工作正常为什么不在阵列内工作? – ngeran

+0

你有[节点ipaddress]为零..? 有没有NSLog这个说法 – Hadi

相关问题