Domanda

I have looked through Apple's DateCell example, unfortunately as all other examples I found it is based on a storyboard. I am trying to create a simple TableViewController with two cells, one for showing the selected date and another for showing a date picker.The Controller will be connected to a bigger app which does not use storyboards. Can somebody write a short guidelines how to recreate the TableView from Apple's example as a XIB and a few sentences regarding the implementation?

Thank you in advance!

È stato utile?

Soluzione

After making a sufficient research on the topic, I managed to build a solution out of two separate tutorials.

My main problem were the dynamic prototype cells used in the storyboard example provided by Apple. Therefore I created a customised cell with UIDatePicker inside. I used this tutorial to customise the cell xib file according to my needs and then used it in the UITableView.

Afterwards I followed this tutorial, only instead of a storyboard I created a UITableViewController and used the custom cell with UIDatePicker inside. This example seemed much easier to follow than the sample code provided by Apple.

I didn't encounter any other problems on the way, but if you have any questions I would gladly try to answer. I am still quite new to iOS and Objective-C, so maybe three is a better and easier solution out there.

Altri suggerimenti

First of all you need to create two custom cells (one for selected date, second for picker), which both are subclasses of UITableViewCell. You also need to create two xib files for them. Then change the class of xib to our custom class and connect outlets. Next import that classes to your UITableViewController. In method viewDidLoad write something:

UINib *customNib = [UINib nibWithNibName:@"CustomNibName" bundle:nil];
[self.tableView registerNib:customNib forCellReuseIdentifier:@"CustomCellIdentifier"];

After that you can use your cells in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method:

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCellIdentifier" forIndexPath:indexPath];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top