7

As I am new in IOS development I am trying to add CustomeCell into tableView but I can not add it from library.

What I am doing is just drag TableView in my ViewController and than drag tableview cell in it but its added as extra view under ViewController 's view not able to add it into tableview.

I am stuck here any idea how can I add cell by drag and drop.

Screen shot :

I know how to add cell by coding but its very lengthy process to add every thing by code.

Any guidence will be appreciated.

Thanks in advance.enter image description hereenter image description here

BhaviDev
  • 194
  • 2
  • 10
  • 1
    Welcome to Stack Overflow! To give you a great answer, it might help us if you have a glance at [ask] if you haven't already. It might be also useful if you could provide a [mcve]. – Mat Jan 18 '17 at 09:29
  • Sure let me add my view screen shot – BhaviDev Jan 18 '17 at 09:31
  • 2
    May be you are working with `XIB` not with `sotryboard`. – Nirav D Jan 18 '17 at 09:33
  • Strange i am not able to add any images as i have no enough stack points. Disgusting restrictions – BhaviDev Jan 18 '17 at 09:44
  • Yes Nirav i am adding tableview cell in viewcontroller xib. – BhaviDev Jan 18 '17 at 09:46
  • 1
    You can not add Cell Prototype in your TableView as your are using XIB only, for that you need to transfer to StoryBoard only. – CodeChanger Jan 18 '17 at 09:52
  • 4
    You can add cell directly in `UITableController` in `UIStoryBoard`, otherwise you can't. – Mohammad Zaid Pathan Jan 18 '17 at 09:54
  • Possible duplicate of [Cannot add a PrototypeCell to UITableView inside xib file](https://stackoverflow.com/questions/34331947/cannot-add-a-prototypecell-to-uitableview-inside-xib-file) – vrwim Feb 28 '18 at 15:08

3 Answers3

4

As per my experience, you can not add Custom Cell into TableView while you are using or editing your ViewController/View/Cell into XIB.

For that you have 2 options

1st: Use Storyboard to design your TableViewCell.

2nd: Create a new custom cell with XIB and load it into your tableView with NIB name like below.

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
if (cell == nil) {
   // Create a temporary UIViewController to instantiate the custom cell.
   NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" 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];
}

Hope this will help to add cells into XIB.

CodeChanger
  • 7,953
  • 5
  • 49
  • 80
0

I'm sorry for late answer, if you're using xib layout check this;

Cannot add a PrototypeCell to UITableView inside xib file

ali ozkara
  • 5,425
  • 2
  • 27
  • 24
-1

For this first select your TableView and in the Inspector Window Increase Prototype Cells by 1 as shown in ScreenShot

enter image description here

NSNoob
  • 5,548
  • 6
  • 41
  • 54
Gurinder Batth
  • 655
  • 9
  • 18
  • Sorry but there is no prototype cell option in attribute inspector. – BhaviDev Jan 18 '17 at 09:31
  • Do you select your tableview first – Gurinder Batth Jan 18 '17 at 09:31
  • Yes i have selected tableview but there is no option like prototype cell. – BhaviDev Jan 18 '17 at 09:45
  • I think you are using Static Cell. If you are your Simple tableview in UIViewController then you can't add Static Cells in Table view for Static Cells you have to use UITableViewController. you got my point – Gurinder Batth Jan 18 '17 at 09:48
  • I dont know its static cell or dynamic but i need to use that into my tableview. May be uts dynamic one but here my problem is i am not able to add any cell. – BhaviDev Jan 18 '17 at 09:55
  • In the Attribute Inspector there is `Content` Select it and set it as Dynamic Prototypes as seen in above image and then select Prototype Cells – Gurinder Batth Jan 18 '17 at 09:58
  • 2
    @GurinderBatth as User is using XIB there is no option like prototype cells as You can not add Prototype cell into XIB.But Yes your answer is right if User is using StoryBoard, because storyboard have prototype cell option and we can add both static and dynamic cell into it. – CodeChanger Jan 18 '17 at 10:02
  • hmm Right @CodeChanger for this we have to add another Xib as UITableViewCell and give them UITableViewCell class and add in tableview data source metho – Gurinder Batth Jan 18 '17 at 10:06