Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-08-2010, 07:31 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 19
dragi is on a distinguished road
Default Question on how to add a UIview as a subview to a UITableCell

Hello users,

I've got a question on how to add a UIView to a UITableViewCell.

In my learning Project I've got a UITableViewController (TableTestViewController, a UITabelViewCell.xib (MainTabelCell.xib) and a UIView (InnerTableView). My Goal ist to show the MainTableCell in the UITableView and in this MainTabelCell the InnerTabelView but I only manage to show the Cell in the Table.

TableTestViewController.h:

Code:
#import <UIKit/UIKit.h>
#import "InnerTableView.h"

@interface TableTestViewController : UITableViewController {

    UITableView *mainTable;
    UITableViewCell *nibLoadedCell;
    InnerTableView *innerView;
}

@property(nonatomic, retain) IBOutlet UITableView *mainTable;
@property(nonatomic, retain) IBOutlet UITableViewCell *nibLoadedCell;
@property(nonatomic, retain) InnerTableView *innerView;

@end
TableTestViewController.m:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"MainTableCell"
            owner:self options:NULL]; 
        cell = nibLoadedCell;
    }

    // Configure the cell.
    innerView = [[UIViewController alloc] init];
    [cell addSubview: innerView.view];
    return cell;
}
Does anyone have an Idea why the innerView will not be shown in the TabelViewCell? What did I miss here? I'm still learning all that stuff but after 5 hours I don't find a clue in my Books. Hope this is not a to dumb question

Thank you

dragi
dragi is offline   Reply With Quote
Old 07-08-2010, 07:56 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

If you already have a nib-based cell, why are you manually adding a view in code? Add it to your nib.

And this:
Code:
innerView = [[UIViewController alloc] init];
[cell addSubview: innerView.view];
return cell;
...is not a good way to accomplish this. There is no reason to use an instance variable like this, and you are leaking the view.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-08-2010, 08:08 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 19
dragi is on a distinguished road
Default

OK,

this is basicly a test and I want to learn. What I really need is a View with it's own controller in a cell, I guess the UITableViewCell.xib is not necessary for that.
The UIview inside a Cell will be a container for a horizontal scrolling table. So that you get a UI ike the one from Pulse. But I don't get it on how to add a View to a Cell where the View has it's own Controller Class. As far as I know I have to create an instance from the controllerclass to get the View and put that one in a Cell...or not?!
I hope it becomes a bit clearer on what I try to do.

Thank you

dragi
dragi is offline   Reply With Quote
Old 07-08-2010, 09:54 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Ok, I just realized I misread your code. You're not leaking the view, you're leaking the view controller.

But, in general it sounds like you know what to do. You really should use a property instead of the instance variable for the view controller. Is there a problem you are encountering?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 07-08-2010, 10:06 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2008
Posts: 19
dragi is on a distinguished road
Default

OK, Now I know what you meant with the leak and I'm going to fix that. The Problem is that the UIView is not shown in the Cell and I don't know why?! I can see the Custom Cell from the nib but it has not my UIView in it at runtime.
dragi is offline   Reply With Quote
Old 07-08-2010, 12:05 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, the code above you are using a generic view controller. There really isn't much to see.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
subview, uitableview, uitableviewcell

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
13 members and 332 guests
akacaj, cgokey, esoteric, EXOPTENDAELAX, GHuebner, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sloshmonster, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:23 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0