-1

Hi I am trying to use a tableview on my uiviewcontroler on my .h I put this code:

@interface SecondViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *myTableView;
}
@property (nonatomic, retain) IBOutlet UITableView *myTableView;

and on my .m:

I modify my code but now it says my Response_array is undeclared and also myTablevView not found on object type uitableviewcell

@synthesize myTableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_responseArray count];
}
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] init];
}
NSString *cellValue = [_responseArray objectAtIndex:indexPath.row];
[cell.textLabel setText:cellValue];
 return cell;
}

Here is my Response_array

NSArray* Response_array = [json objectForKey:@"avenidas"];
9
  • 1
    What line is the error on?
    – jscs
    Commented May 19, 2013 at 18:15
  • on the -(UITableViewCell *)myTableView line
    – darkjuso
    Commented May 19, 2013 at 18:43
  • -(UITableViewCell *)myTableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath will not be called and will cause an error because the delegate method is declared incorrectly. It should be -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath Also, check to make sure you have a beginning and ending bracket { } before and after the method body.
    – Jonathan
    Commented May 19, 2013 at 19:26
  • thanks that work but now I have other errors
    – darkjuso
    Commented May 19, 2013 at 19:38
  • @darkjuso, No problem! I'm glad that helped. I've provided an answer below.
    – Jonathan
    Commented May 19, 2013 at 20:12

2 Answers 2

0

Problem: Response_array is undeclared

In your @interface file create a property that declares your NSArray

@property (retain, nonatomic) NSArray * responseArray;

In your @implementation file @synthesize the property

@synthesize responseArray = _responseArray;

(Optional)

In -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

You can use the tableView parameter to access the tableView instead of the myTableView property.

Example:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}

Problem: myTablevView not found on object type uitableviewcell

cell.myTableView = cellValue;

You are trying to access a tableView within your cell? The UITableViewCell has a default label called textLabel.

So it should be as follows (unless you have a custom Label):

[cell.textLabel setText:cellValue];
0
0

It looks like you have a nested method there.

In other words, you have a method that is essentially:

- (IBAction)Avenida:(id)sender {

    -(UITableViewCell *)myTableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

    }

}

No wonder your code isn't compiling.

You need to extract your "cellForRowAtIndexPath" method out from your "Avenida" action method. These should be two separate methods.

3
  • I put the cellForRowAtIndexPath out still getting the "Invalid argument type UITableViewCell to unary expression" error
    – darkjuso
    Commented May 19, 2013 at 18:44
  • I manage to put it out and now I modify my original post with a new error
    – darkjuso
    Commented May 19, 2013 at 19:37
  • so now you have a new problem? This would be a great opportunity to post a separate and new question. :-) In any event, I am glad I was able to help you out with solving the first problem. In which function is your "Response_Array" declared? You should make it an instance variable (i.e. put it in your "@interface" .h file). Commented May 19, 2013 at 19:39

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.