0

first of all I've checked a lot of posts in here, but i couldn't find a proper solution. I'm new to ObjC so i'm not able to find a solution by myself! Problem: I have a TabBArController with 2 Tabs each of them holds a TableviewController. From my first ViewController i'm tryin to add different Url strings to an Array of my SecondTableViewController.

Method from FirstviewController which should add the url to the Array of the 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
    }

}

here is my 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);

}

Thanks for your time!!

Konduktor
  • 1
  • 1

1 Answers1

0

You need to initialize the array first

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

OR

NSArray *arr = [[NSArray alloc]initWithObjects:urlString, nil];
[tAVC setTabbleArr:arr];
yunas
  • 4,143
  • 1
  • 32
  • 38
  • Thanks for your answer. I tried both solutions, but they did not work out. The array is still empty. – Konduktor Apr 26 '13 at 08:27
  • remove this line if(!self.tabbleArray) { self.tabbleArray = [NSMutableArray array]; } – yunas Apr 26 '13 at 09:27
  • and check the following things, if ur urlString is correct and if u push/use the right controller. – yunas Apr 26 '13 at 09:29
  • Sry for asking like a dummy, but what do you mean with push/use the right controller? I removed the if line, but nothing happened. – Konduktor Apr 29 '13 at 06:33
  • If I add this line: [self.navigationController pushViewController:tAVC animated:YES]; My app crashes with this error: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'TableAnswerController'' *** First throw call stack:.... – Konduktor Apr 29 '13 at 06:55
  • Thanks For your Help! I figured it out by myself. I used the AppDelegate to create an NSMutableArray which is used somehow like a global variable. http://stackoverflow.com/questions/6061659/use-nsmutablearray-in-app-delegate-in-another-class – Konduktor Apr 29 '13 at 07:56