0

首先,我在这里检查了很多帖子,但我找不到合适的解决方案。我是 ObjC 的新手,所以我无法自己找到解决方案!问题:我有一个带有 2 个选项卡的 TabBArController,每个选项卡都有一个 TableviewController。从我的第一个 ViewController 中,我尝试将不同的 Url 字符串添加到我的 SecondTableViewController 的数组中。

FirstviewController 中的方法应该将 url 添加到 SecondViewController 的数组中:

- (IBAction)setJobs:(id)setJobs
{
    NSString *parameterString = [[NSString alloc]init];
    for (UITextField*textField in textFields)
    {
        parameterString = [parameterString stringByAppendingString:[NSString    stringWithFormat:@"%@,",textField.text]];
    }

    NSString*user = [[NSString alloc]init];
    NSString*password = [[NSString alloc]init];
    NSString*firmenId = [[NSString alloc]init];

    user = [[NSUserDefaults standardUserDefaults] objectForKey:@"Username"];
    password = [[NSUserDefaults standardUserDefaults] objectForKey:@"Password"];
    firmenId = [[NSUserDefaults standardUserDefaults] objectForKey:@"FirmenId"];

    NSString*urlString=[[NSString alloc]initWithFormat:@"http://www.someurl.com/firmenid=%@;projectid=%@;user=%@;kennwort=%@;appparminfo=%@",firmenId,[self.detailRowArray objectAtIndex:1],user,password,parameterString];

    [projektsInUse addObject:urlString];


    // Here the url should be passed to the other Viewcontroller
    TableAnswerController *tAVC=[[TableAnswerController alloc]init];
    [tAVC.tabbleArray addObject:urlString];



    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:15.0];
    NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
    if(connection)
    {
        //connection didReceiveData
    }
    else
    {
        // Error Handling
    }

}

这是我的 SecondTableViewController:

#import "TableAnswerController.h"

@interface TableAnswerController ()

@end

@implementation TableAnswerController

@synthesize timer,tabbleArray;



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

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(!self.tabbleArray)
    {
        self.tabbleArray = [NSMutableArray array];
    }
}
- (IBAction)refreshAnswers:(id)sender
{
    NSLog(@"TableArray: %@",tabbleArray);

}

谢谢你的时间!!

4

1 回答 1

0

您需要先初始化数组

TableAnswerController *tAVC=[[TableAnswerController alloc]init];
 tAVC = [NSMutableArray new];
[tAVC.tabbleArray addObject:urlString];

或者

NSArray *arr = [[NSArray alloc]initWithObjects:urlString, nil];
[tAVC setTabbleArr:arr];
于 2013-04-26T08:17:30.533 回答