Reputation: 9392
In a table view, I want to add a date picker cell to it, but there wasn't an option for it, so I tried to make a custom cell, but I didn't know how to. Does anyone know how to make a custom cell or is there a good tutorial for beginner about it. Thanks.
Upvotes: 0
Views: 768
Reputation: 22948
Okay, so, after discovering that embedding an NSDatePickerCell in the NSTableColumn in a nib is not allowed, I went on to see if it was possible to do this programmatically. Sample project is at:
http://www.markdouma.com/developer/TableViewDatePicker.zip
As the test app shows, it is possible to do this programmatically:
You'd use code like the following:
NSDatePickerCell *cell = [[[NSDatePickerCell alloc] init] autorelease];
[dateOfHireColumn setDataCell:cell];
However, as you can see, the initial result isn't really what one would like. The date picker cell doesn't reverse the text color it draws with when it's selected, and also, it doesn't really allow you to change the date via its controls.
While I haven't looked into trying to do this extensively (in other words, perhaps with a bit of tweaking and/or subclassing you could get it to work better), the lower table view shows an example of how it could be implemented. Basically, you simply use a regular text field in the table column, along with an NSDateFormatter to have the date show properly. When you select the date, you can use the NSDatePicker below the table to edit the value.
Upvotes: 2
Reputation: 2742
I would say, use a normal UITableViewCell and show a UIAlertView with an embedded UIPickerView.
After setting the date in the UIAlertView you could place the variable in your tableCell. A UIPickerView is much to big to display inside a Cell.. But, also that can be done..!
I would use this method.
Hope it helps you..
Upvotes: 0
Reputation: 1559
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UIImage *image = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,300,40) reuseIdentifier:CellIdentifier] autorelease];
}
Now after this enter your code and end the braces for cellForRowAtIndexPath method.
Try this out. Shruti
Upvotes: 2