Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Tableview with custom cell not working

KingofChaosKingofChaos Posts: 25Registered Users
Hey everyone, I have this code so far for my tableview with custom cells,

#import \"ViewController.h\"

@interface ViewController ()

@end

@implementation ViewController
@synthesize tableView1;
@synthesize array;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

grommetext1.keyboardType = UIKeyboardTypeNumberPad;


}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma mark

- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}

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

{



NSString *uniqueIdentifier = @\"customerCell\";



CustomerCell *cell = nil;

cell = (CustomerCell *) [self.tableView1 dequeueReusableCellWithIdentifier:uniqueIdentifier];

CustomerCell *array = [self.array objectAtIndex:[indexPath row]];

if(!cell)

{



NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@\"CustomerCell\" owner:nil options:nil];

for(id currentObject in topLevelObjects)

{

if([currentObject isKindOfClass:[CustomerCell class]])

{

cell = (CustomerCell *)currentObject;

break;

}

}

}


cell.label1.text = cell.name;


return cell;

}



@end


but it keeps giving me the error "property 'name' not found on object of type 'CustomerCell'" and I dont know how to declare the property, Thank you for any help you can give.
Post edited by KingofChaos on

Replies

  • DomeleDomele Posts: 2,948Registered Users
    Edit: Never mind. Read the code way too quickly, look at Duncan C's post.
    If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.



    New app - See screenshots and details at www.globaclock.com.



    If you want to
  • Duncan CDuncan C Posts: 8,025Tutorial Authors, Registered Users
    KingofChaos;440446 said:
    Hey everyone, I have this code so far for my tableview with custom cells,

    #import \"ViewController.h\"

    @interface ViewController ()

    @end

    @implementation ViewController
    @synthesize tableView1;
    @synthesize array;


    - (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    grommetext1.keyboardType = UIKeyboardTypeNumberPad;


    }

    - (void)viewDidUnload
    {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    }

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }

    #pragma mark

    - (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section
    {
    return [self.array count];
    }

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

    {



    NSString *uniqueIdentifier = @\"customerCell\";



    CustomerCell *cell = nil;

    cell = (CustomerCell *) [self.tableView1 dequeueReusableCellWithIdentifier:uniqueIdentifier];

    CustomerCell *array = [self.array objectAtIndex:[indexPath row]];

    if(!cell)

    {



    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@\"CustomerCell\" owner:nil options:nil];

    for(id currentObject in topLevelObjects)

    {

    if([currentObject isKindOfClass:[CustomerCell class]])

    {

    cell = (CustomerCell *)currentObject;

    break;

    }

    }

    }


    cell.label1.text = cell.name;


    return cell;

    }



    @end


    but it keeps giving me the error "property 'name' not found on object of type 'CustomerCell'" and I dont know how to declare the property, Thank you for any help you can give.

    Post the header for your custom cell type CustomerCell.

    Also post the code that is throwing the error. I did not see any reference to "name" in the code you posted.

    You might need to cast a generic cell to a CustomerCell before you can reference a property from your custom cell.


    Part of the code you posted does not make sense to me. First you try to dequeue a reusable cell, which is fine. Then you try to extract another CustomerCell object that you call "array". If it's a custom table view cell, why do you call it array? And why are you storing table view cells to an array? The name "array" is a very confusing name for a table view cell. And, you should not be saving your table view cells into an array. That will prevent the system from deallocating them when it is done with them.

    This is the code I am talking about.

        cell = (CustomerCell *) [self.tableView1 dequeueReusableCellWithIdentifier:uniqueIdentifier];

    //The following line does not make sense to me.
    CustomerCell *array = [self.array objectAtIndex:[indexPath row]];
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • KingofChaosKingofChaos Posts: 25Registered Users
    Thank you for the replies, this is my CustomerCell.h file

    #import <UIKit/UIKit.h>

    @interface CustomerCell : UITableViewCell
    {

    }

    @property (nonatomic, strong) IBOutlet UILabel *label1;
    @property (nonatomic, strong) IBOutlet UIImageView *image1;

    @end


    And I just followed a tutorial and did what they told me to do, Im still a beginner, and am trying to learn how a tableview works with custom cells.
  • KingofChaosKingofChaos Posts: 25Registered Users
    Sorry, forgot one of your questions, this is the line that is giving me the error:

    cell.label1.text = cell.name;
  • Duncan CDuncan C Posts: 8,025Tutorial Authors, Registered Users
    KingofChaos;440495 said:
    Sorry, forgot one of your questions, this is the line that is giving me the error:

    cell.label1.text = cell.name;

    Post the whole method that contains that line and put that line in bold.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • KingofChaosKingofChaos Posts: 25Registered Users
    I got that working, I just had to change the ".name" to "@"whatever""

    Now I'm using this code:

    - (CustomerCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomerCell *cell = [tableView dequeueReusableCellWithIdentifier:@\"customerCell\"];
    if (cell == nil) {
    // Load the top-level objects from the custom cell XIB.
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@\"CustomerCell\" owner:self options:nil];
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
    cell = [topLevelObjects objectAtIndex:0];
    }

    return cell;
    }


    And I get this error in the output:

    2012-07-09 13:44:44.346 LYWAM Tour[394:10703] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x761f280> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image1.'
    *** First throw call stack:
    (0x17a2022 0x28abcd6 0x17a1ee1 0xe44022 0xdb5f6b 0xdb5edb 0xdd0d50 0x6b871a 0x17a3dea 0x170d7f1 0x6b726e 0x6b8eb7 0x2e98 0x530c54 0x5313ce 0x51ccbd 0x52b6f1 0x4d4d42 0x17a3e42 0x22f7679 0x2301579 0x22864f7 0x22883f6 0x2287ad0 0x177699e 0x170d640 0x16d94c6 0x16d8d84 0x16d8c9b 0x2e447d8 0x2e4488a 0x496626 0x28ad 0x2815)
    terminate called throwing an exception(lldb)
Sign In or Register to comment.