How do I replace the date with a writable title? - iphone

When I add a new row, it currently adds a new row with the current date as the title. Below is the code that I have. What do I change "NSDate date" to so that the user can input whatever title they want?
(void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

You could use the new UIAlertView with plain text entry. You'll also have to change your table view cell to display an NSString instead of an NSDate. (Oh, and you have to adopt the UIAlertViewDelegate in the class.
-(void)insertNewObject:(id)sender
{
UIAlertView * getTitle = [[UIAlertView alloc] initWithTitle:#"title" message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil]; // should give proper cancel/accept buttons
getName.alertViewStyle = UIAlertViewStylePlainTextInput;
[getTitle show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
NSString * userEnteredThisString = [[alertView textFieldAtIndex:0] text];
[_objects insertObject:userEnteredThisString atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}

Related

Unable to update uitableview rows

I am trying to update selected rows of UITableView from UIAlertView inside didSelectRowAtIndexPath. But I am facing a problem. Each time I try to update any row, it's only updates the first row irrespective of selection of row.
My code is:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedrow = nil;
if (searching) {
slCell=indexPath.row;
selectedrow = [copyListOfItems objectAtIndex:indexPath.row];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter the Number of Quantity" message:#""
delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert addTextFieldWithValue:#"" label:#"Number of Item"];
textfieldQty = [alert textFieldAtIndex:0];
textfieldQty.keyboardType = UIKeyboardTypeNumberPad;
textfieldQty.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldQty.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
[alert release];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Enter the Number of Quantity" message:#""
delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert addTextFieldWithValue:#"" label:#"Number of Item"];
textfieldQty = [alert textFieldAtIndex:0];
textfieldQty.keyboardType = UIKeyboardTypeNumberPad;
textfieldQty.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldQty.autocorrectionType = UITextAutocorrectionTypeNo;
[alert show];
[alert release];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *b=nil;
if (buttonIndex == 0) {
if (searching) {
if([textfieldQty.text isEqualToString:b]) {
UIAlertView *alert2 = [[UIAlertView alloc] initWithTitle:#"Enter plz" message:#""
delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK"];
[alert2 show];
[alert2 release];
}
NSString *newqty = [[NSString alloc] initWithFormat:#"%#",textfieldQty.text];
DMSAppDelegate *d= (DMSAppDelegate *)[[UIApplication sharedApplication] delegate];
[d->tableDataQt replaceObjectAtIndex:slCell withObject:(id)newqty];
NSLog(#"tb%#",copyListOfQty);
}
else {
NSString *newqty = [[NSString alloc] initWithFormat:#"%#",textfieldQty.text];
DMSAppDelegate *d= (DMSAppDelegate *)[[UIApplication sharedApplication] delegate];
[d->tableDataQt replaceObjectAtIndex:slCell withObject:(id)newqty];
[self.tablevieww reloadData];
}
}
}
Please follow below steps to achieve what you want.
While creating UIAlertview in (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath method, set alerview's tag as indexpath's row.
In delegate method -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex, you try to access alertView's tag and pass that tag to the method call [d->tableDataQt replaceObjectAtIndex:[alertView tag] withObject:(id)newqty];
In AppDelegate class, you create one more method called -(void)replaceObjectAtIndex:(NSInteger>inIndex withObject:(id)inObject
In above newly created method try to access UITableViewCell from UITableView object with method call UITableViewCell *myCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:inIndex inSection:0];
This way, you will get the object of UITableViewCell and alter the value of that and reload the table.
I hope this will help you. Please do not forget to put right mark if this resolves your problem. :)
Thanks.

Using ARC and UITableViewController is throwing Observation info was leaked, and may even become mistakenly attached to some other object

I cannot seem to figure out what to do to resolve this error that I am receiving. I click on a cell which pops a new UITableViewController onto the stack. Once I hit the back button on the Navigation UI when in this controller I receive this error in the debugger but there doesn't seem to be any issue with the app as it doesn't crash or hang and still works fine.
An instance 0x79a8400 of class UITableView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
(
Context: 0x0, Property: 0x738c010>
)
Code is below and I am using similar code on other UITableViewControllers but not receiving the error.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self)
{
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
pull = [[PullToRefreshView alloc] initWithScrollView:(UIScrollView *) self.tableView];
[pull setDelegate:self];
[self.tableView addSubview:pull];
[tableView.dataSource self];
[tableView.delegate self];
NSString *isAuthenticated = [[NSString alloc] init];
isAuthenticated = [self retrieveUserToken:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"]];
NSNumber *categorySelected = [[NSNumber alloc] init];
categorySelected = [[NSUserDefaults standardUserDefaults] valueForKey:#"category_id"];
if (![isAuthenticated length])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}else if (categorySelected ==nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"alert" message:#"message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}
[self getTableViewData];
}
- (void)viewDidUnload
{
[self setTableView:nil];
pull = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSString *)retrieveUserToken:(NSString *)user
{
NSError *error = nil;
NSString *username = user;
return [SFHFKeychainUtils getPasswordForUsername:username andServiceName:#"app" error:&error];
}
- (void)getTableViewData
{
URLSingleton *urls = [[URLSingleton alloc] init];
responseData = [NSMutableData data];
NSNumber *categoryID = [[NSNumber alloc] init];
categoryID = [[NSUserDefaults standardUserDefaults] valueForKey:#"category_id"];
NSString *urlComplete = [[NSString alloc] init];
urlComplete = [urls getEvent:categoryID];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlComplete]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[connection start];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return categories.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
cell.textLabel.textColor = [UIColor blackColor];
cell.textLabel.text = [categories objectAtIndex:indexPath.row];
return cell;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message." delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[pull finishedLoading];
[alert show];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [responseString JSONValue];
NSArray *response = [dictionary valueForKey:#"name"];
NSArray *responseID = [dictionary valueForKey:#"id"];
categories = [[NSMutableArray alloc] initWithArray:response];
eventID = [[NSMutableArray alloc] initWithArray:responseID];
[self.tableView performSelectorOnMainThread:#selector(reloadData) withObject:nil waitUntilDone:NO];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[pull finishedLoading];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
int i = 0;
for(NSString *name in categories)
{
if ([name isEqualToString:cellText])
{
[[NSUserDefaults standardUserDefaults] setValue:[eventID objectAtIndex:i] forKey:#"event_id"];
[[NSUserDefaults standardUserDefaults] setValue:cellText forKey:#"event_name"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
i++;
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
if(checkedIndexPath) {
UITableViewCell* uncheckCell = [self.tableView
cellForRowAtIndexPath:checkedIndexPath];
uncheckCell.accessoryType = UITableViewCellAccessoryNone;
}
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
checkedIndexPath = indexPath;
}
-(void)tableView:(UITableView*)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
URLSingleton *urls = [URLSingleton sharedInstance];
NSNumber *event = [[NSNumber alloc] init];
if(editingStyle == UITableViewCellEditingStyleDelete)
{
UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
NSString *cellText = selectedCell.textLabel.text;
int i = 0;
for(NSString *name in categories)
{
if ([name isEqualToString:cellText])
{
event = [eventID objectAtIndex:i];
[eventID removeObjectAtIndex:i];
}
i++;
}
NSString *reqURL = [[NSString alloc] initWithString:[urls deleteEvent:[event stringValue]]];
NSURLRequest *delReq = [NSURLRequest requestWithURL:[NSURL URLWithString:reqURL]];
NSURLResponse *resp = nil;
NSError *err = nil;
NSData *response = [NSURLConnection sendSynchronousRequest:delReq returningResponse: &resp error: &err];
NSString *reply = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
SBJsonParser *parser = [SBJsonParser new];
id content = [reply JSONValue];
if(!content){
NSLog(#"%#", parser.errorTrace);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
return;
}
NSNumber *status = [content valueForKey:#"success"];
NSNumber *one = [[NSNumber alloc] initWithInt:1];
if ([status isEqualToNumber:one])
{
[categories removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
}
}
}
- (void)pullToRefreshViewShouldRefresh:(PullToRefreshView *)view;
{
NSString *isAuthenticated = [[NSString alloc] init];
isAuthenticated = [self retrieveUserToken:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"]];
NSNumber *categorySelected = [[NSNumber alloc] init];
categorySelected = [[NSUserDefaults standardUserDefaults] valueForKey:#"category_id"];
if (![isAuthenticated length])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}else if (categorySelected ==nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}
[self getTableViewData];
}
- (IBAction)createEvent:(id)sender
{
NSString *isAuthenticated = [[NSString alloc] init];
isAuthenticated = [self retrieveUserToken:[[NSUserDefaults standardUserDefaults] valueForKey:#"email"]];
NSNumber *categorySelected = [[NSNumber alloc] init];
categorySelected = [[NSUserDefaults standardUserDefaults] valueForKey:#"category_id"];
if (![isAuthenticated length])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Message" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}else if (categorySelected == nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert" message:#"Alert" delegate:self cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[alert show];
return;
}
AddEventViewController *aevc = [self.storyboard instantiateViewControllerWithIdentifier:#"AddEventViewController"];
[self.navigationController popToViewController:aevc animated:YES];
}
I fixed it by adding the following method
- (void)dealloc
{
[self.tableView removeObserver:pull forKeyPath:#"contentOffset"];
}

Issue removing core data entry by selecting a row on table view

Using core data to populate my table view. The thing I am not getting is that how can I delete a single entry from the core data.
I am using uitableview not the controller.
Here is the code I am using:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == favouritesTable) {
cellValue = [licensePlateArray objectAtIndex:indexPath.row];
} else { // handle search results table view
cellValue = [filteredListItems objectAtIndex:indexPath.row];
}
static NSString *CellIdentifier = #"vlCell";
VehicleListCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog(#"Cell Created");
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"VehicleListCell" owner:nil options:nil];
for (id currentObject in nibObjects) {
if ([currentObject isKindOfClass:[VehicleListCell class]]) {
cell = (VehicleListCell *)currentObject;
}
}
UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(tableCellPressed:)];
pressRecongnizer.view.tag = indexPath.row;
pressRecongnizer.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:pressRecongnizer];
[pressRecongnizer release];
}
cell.textLabel.font = [UIFont systemFontOfSize:10];
Favouritesdata *favdata = [licensePlateArray objectAtIndex:indexPath.row];
[[cell ignition] setImage:[UIImage imageNamed:#"ignition.png"]];
[[cell direction] setImage:[UIImage imageNamed:#"south.png"]];
cell.licPlate.text = [favdata licenseplate];
NSLog(#"cellvalue for cellforRow: %#", cell.licPlate.text);
return cell;}
In the method of UILongPressGestureRecognizer:
- (void)tableCellPressed:(UILongPressGestureRecognizer *)recognizer{
if (recognizer.state != UIGestureRecognizerStateBegan) {
return;
}
VehicleListCell* cell = (VehicleListCell *)[recognizer view];
cellValueForLongPress = cell.licPlate.text;
NSLog(#"cell value: %#", cellValueForLongPress);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil] ;
alert.tag = recognizer.view.tag;
[alert addButtonWithTitle:#"Remove from Favourites"];
[alert addButtonWithTitle:#"Take to Map"];
[alert show];}
here in alert view method the selected row will be deleted (if([title isEqualToString:#"Remove from Favourites"])):
-(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alert buttonTitleAtIndex:buttonIndex];
NSManagedObjectContext *contextFav = [app managedObjectContext];
Favouritesdata * favourites = [NSEntityDescription insertNewObjectForEntityForName:#"Favouritesdata" inManagedObjectContext:contextFav];
if([title isEqualToString:#"Remove from Favourites"])
{
NSLog(#"cellValueForLongPress: %#", cellValueForLongPress);
///////// to remove the object from core data
[licensePlateArray removeObjectAtIndex:alert.tag];
}
else if([title isEqualToString:#"Take to Map"])
{
NSLog(#"Go to MapView");
}
NSError *error;
if (![context save:&error]) {
NSLog(#"Error Occured");
}
[favouritesTable reloadData];}
Write this in cellForRowAtIndexPath
UILongPressGestureRecognizer *pressRecongnizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(tableCellPressed:)];
pressRecongnizer.view.tag = indexPath.row;
pressRecongnizer.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:pressRecongnizer];
[pressRecongnizer release];
and use alertview like this
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil] ;
alert.tag = recognizer.view.tag;
[alert addButtonWithTitle:#"Remove from Favourites"];
[alert addButtonWithTitle:#"Take to Map"];
[alert show];
then write this in -(void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
[YourArray removeObjectAtIndex:alert.tag];
[YourTable reloadData];
Please use this code at appropriate place in your code..
Happy Coding..

Custom delete button in uitableview cell don't work

I made tableView with filteredReservations array wich contains Rezervacija objects.
I added custom button "board", and when button is clicked, I ask with alert view to confirm this and then sending request to server. When receive server's response I need to delete row from table and object from filteredReservations array.
When I delete first row it's ok, but after that in filteredReservations instead of Rezervacija object, I got UIButton objects! I don't know HOW :)
Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return([filteredReservations count]);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
Reservation *reservation = [filteredReservations objectAtIndex:indexPath.row];
NSString *label = [[NSString alloc] initWithFormat:#"%# (%d)", reservation.name, reservation.seatsNumber];
cell.textLabel.text = label;
[label release];
[reservation release];
tableView.allowsSelection = FALSE;
UIButton *cellButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cellButton setFrame:CGRectMake(430.0, 2.0, 106.0, 40.0)];
[cellButton setTitle:#"Board" forState:UIControlStateNormal];
[cellButton addTarget:self action:#selector(BoardPassengers:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:cellButton];
cellButton.tag = indexPath.row;
return cell;
}
-(void)BoardPassengers:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Question" message:#"Do you want to board passengers?"
delegate:self cancelButtonTitle:#"Odustani" otherButtonTitles:#"Da", nil];
[alert show];
[alert release];
passengerForBoarding = [NSIndexPath indexPathForRow:((UIControl*)sender).tag inSection:1];
}
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
NSLog(#"cancel");
}
else
{
Reservation *reservationNew = [filteredReservations objectAtIndex:passengerForBoarding.row];
NSString *reservationId = [[NSString alloc] initWithFormat:#"%d",reservationNew.reservationId];
params = [NSDictionary dictionaryWithObjectsAndKeys: #"1", #"tour_id", #"1", #"bus_number",reservationId, #"reservation_id", nil];
[[RKClient sharedClient] post:#"/service/boardingToBus.json" params:params delegate:self];
[DSBezelActivityView newActivityViewForView:self.view withLabel:#"Boarding..."];
}
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
if([[request resourcePath] isEqualToString:#"/service/boardingToBus.json"]){
if([[response bodyAsString] isEqualToString:#"ERROR"]){
[DSBezelActivityView removeViewAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Error."
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}else{
[DSBezelActivityView removeViewAnimated:YES];
[filteredReservations removeObjectAtIndex:passengerForBoarding.row];
[self.tableView reloadData];
//[self.tableView beginUpdates];
//[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:passengerForBoarding]
// withRowAnimation:UITableViewRowAnimationFade];
// NSLog(#"%i", passengerForBoarding.row);
//[self.tableView endUpdates];
}
}
}
It sounds like you need to make sure the table view is explicitly aware of how many filtered reservations it needs to display.
// assuming only one section for your table view
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return([filteredReservations count]);
}
For more info:
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UITableViewDataSource/tableView:numberOfRowsInSection:
Hey you can get the value of "Reservation ID" By this.
-(void)BoardPassengers:(id)sender{
Reservation *reservationNew = [filteredReservations objectAtIndex:[sender tag]];
NSString *reservationId = [NSString StringWithFormat:#"%d",reservationNew.reservationId];}
Or you can use this value anywhere you want like you have mentioned via alert-box.

How to get all rows of same group in TableView

Please help me to get all rows of same group in tableView. i am using below code to show radio/check in groups of tableview and want the only one per group selection.
so for that i have got 2 images
1:uncheck
2:checked
so when user will click/select a row of group than i am changing its cell.image to "checked" and its working but don't know how to make all other cell's images of same group's to "unchecked"
dont know how to loop through (get) all rows/cells of current group
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *listData =[self.tableContents objectForKey:
[self.sortedKeys objectAtIndex:[indexPath section]]];
NSUInteger row = [indexPath row];
NSString *rowValue = [listData objectAtIndex:row];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.image = [UIImage imageNamed:#"checkbox-checked.png"];
NSString *message = [[NSString alloc] initWithFormat:rowValue];
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"You selected"
message:message delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
[message release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Here is a possible workaround:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Store the section in your class
NSUInteger section = indexPath.section;
self.section = section; // remember to declare instance variable, property, synthesize
self.row = row; // remember to declare instance variable, property, synthesize
[tableView reloadData];
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == self.section) {
if (indexPath.row != self.row) {
// then do UNCHECK here
}
}
}
If you know how many rows in your current section, you don't need to call reloadData, just call [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:YOUR_ROW inSection:YOUR_SECTION];