NSArray With 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;
}

您添加到数组中的所有字符串甚至还没有被分配/初始化。这就是为什么数组是空的。你不能只写:NSString *emptyString;然后再写:[myArray addObject:emptyString];

检查从表视图传递的值。它们可能是零。我只是用了这么多的数据,我得到了正确的NSLog。

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

问题解决了我的代码很好。问题是:它放错地方了。

代码应该在- (void)viewDidLoad中而不是在- (id)initWithStyle:

我要感谢每一个花时间来研究它的人。我不知道为什么我把代码放在那里开始。

thank x Again

最新更新