Is this normal behavior for UITableViewCellAccessoryDetailDisclosureButton - ios

I notice when I set MessageTableViewCell accessoryType =UITableViewCellAccessoryDetailDisclosureButton and I tab on the "arrow button" itself, the pop menu that is declared on didSelectRowAtIndexPath: don't show up??!!! it works fine if I tabbed on the other area of cell, except on the "arrow button" itself,
However, if I used UITableViewCellAccessoryDisclosureIndicator cell accessory type instead, it works fine, even if I tabbed on the arrow itself.
I wonder if this normal behavior, a bug, or I did something wrong.
I prefer UITableViewCellAccessoryDetailDisclosureButton because in my opinion its more clear when you want to get attention of user.
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString* CellIdentifier = #"MessageCellIdentifier";
MessageTableViewCell* cell = (MessageTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = /*[*/[[MessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] /*autorelease]*/;
}
CastNearAppDelegate *appDelegate = (CastNearAppDelegate *)[[UIApplication sharedApplication] delegate];
Message* message = [appDelegate.dataModel messageWithID: indexPath.row];
if (!message.isSentByUser)
{
cell.accessoryType =/*UITableViewCellAccessoryDetailDisclosureButton; */UITableViewCellAccessoryDisclosureIndicator;
}else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
message.bubbleSize = [SpeechBubbleView sizeForText:message.text];
[cell setMessage:message];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UIActionSheet *popupQueryOptions = [[UIActionSheet alloc]
initWithTitle:#"Options for Blocking and Spam Reporting"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Block Sender"
otherButtonTitles:/*#"Block Sender",*/
#"Inappropriate Content",
/*#"Tell a Friend via Facebook",
#"Tell a Friend via Twitter",*/
nil];
popupQueryOptions.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQueryOptions showInView:[UIApplication sharedApplication].keyWindow];
}

They are used for different things. The indicator is just an indicator whereas the button allows you to have a different action e.g. acting like a button.
UITableView has two possible methods that it will call on it's delegate when the cell is tapped.
When the row itself is tapped the following is called
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
When you tap on the accessory then the tableView calls
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
You can also wire these up independently in Interface Builder. So this behaviour is quite deliberate.

When you use the disclosure button, the delegate method tableView:accessoryButtonTappedForRowWithIndexPath: is called instead of tableView:didSelectRowAtIndexPath:.
The disclosure button is usually used for some kind of secondary action of a cell, e.g. in the Wifi settings, it shows options for a network, while tapping the entire cell connects to it.

Related

reload REFrostedViewController

I have implemented the REFrostedViewController and it is truly amazing. The menu is implemented with the correct view controllers (When the correct row is tapped, it goes to the appropriate view controller). However, I am unable to reload the menu with new view controllers and labels depending on the flow of my application.
For example, assume the menu has a row called "Sign In" that will take the user to the "SignInViewController". Let's assume they signed in successfully. I wish to reload the menu so the row now says "Sign Out" and contains the "SignOutViewController".
Can anyone tell me how this can be done? As of now, the menu rows and view controllers are created at initialization within DEMOMenuViewController.m (in the UITableView Delegate methods).
You could do something like this - For simplicity, this code only has a single section in the menu.
#property (strong,nonatomic) NSMutable Array *menuTitles;
-(void) viewDidLoad {
[super viewDidLoad];
self.menuTitles=[[NSMutableArray alloc]init];
[self.menuTitles addObject:#"Login"]; // You can change this later using [self.menuTitles setObject:#"Logout" atIndexedSubscript:0];
[self.menuTitles addObject:#"Item 2"];
...
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex
{
return [self.menuTitles count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = self.menuTitles[indexPath.row];
return cell;
}

TableViewController's cells from .plist file

I am currently making a tableView for my app, and I've got my cells from a .plist file. However I want to be able to enter my second view controller no matter, what cell I click on, the difference should be that the UIText for my second viewController will depend on which cell I click.
So far, I have imagined something like;
if(tableview.tag == 1){
myUIText.text = #"a";
}else if(tableview.tag == 2){
myUIText.text = #"b";
etc.......
Will this work using the same view controller, same UIText? If not, then how?
And how can I set the tags for my array in my .plist file?
I would appreciate your answers
EDIT: Here is a sample of two methods;
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.items count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * id = #"plistdata";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:id forIndexPath:indexPath];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:id];
}
cell.textLabel.text = self.items[indexPath.row];
return cell;
}
More information is certainly needed by I will make some assumptions on your code and see if it helps any. I assume the the text you want to send is the title of the cell the person clicked on. Now how you send that to the next VC will differ depending on if you are using a segue or not. If you are using a segue you can do something like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"mySegue"]) {
UITableViewCell *cell = (UITableViewCell *)sender;
UpcomingViewController *viewController = segue.destinationViewController;
viewController.textView.text = cell.chapterText;
}
}
However if you are using didSelectRowAtIndexPath then:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UpcomingViewController *viewController = [[UpcomingViewController alloc] init];
viewController.textView.text = self.arrayOfChapterText[indexPath.row];
[self.navigationController pushViewController:viewController animated:YES];
}
Now again because your question wasn't very clear on your scenarios I have taken some liberties with what I think you are probably trying to do. I assume that the view controller that will show after you choose an item will have the UITextView as a public property so that you can set it before pushing or segueing to your new view. I also assume in the didSelectRowAtIndexPath that you are using a UINavigationController.
Hope this helps.

UITableViewCell's Accessory View Button is not displaying in ipad portrait mode

I'm new to ios.Please guide me if you found something wrong. Here is my scenario.
UITableViewCell is showing a label and a button. Button should appears only when the cell is selected. As sometime they both get overlaps if label text is large. So decided to add button as Accessory view. Adding button to UITableViewCell's Accessory View is working in iPhone. Button appears in iPad landscape mode only.Its not showing button in iPad portrait mode. Did I miss something. Is there anyone found something similar.
- (void)tableView:(UITableView *)tview didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tview cellForRowAtIndexPath:indexPath];
cell.accessoryView = joinButton;
}
- (void)tableView:(UITableView *)tView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tView cellForRowAtIndexPath:indexPath];
cell.accessoryView = nil;
}
- (void)viewDidLoad{
NSString *joinLabel = NSLocalizedString(#"Join", #"");
self.joinButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[joinButton setTitle:joinLabel forState:UIControlStateNormal];
/* set join button frame **/
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell.isSelected) {
cell.accessoryView = joinButton; // No reason to create a new one every time, right?
}
else {
cell.accessoryView = nil;
}
}
It just shows join button in portrait mode only when its already showing in landscape mode and then you change rotation from landscape to portrait. Again clicking on some other cell does not show button on that particular selected cell. Ideally it should show button every time you click on cell in both orientation mode.
Thanks
Are you reloading table view on rotation?
You have done coding for (cell.accessoryView = joinButton;)in didSelectRowAtIndexPath instead do coding in cellForRowAtIndexPath of UITableViewDataSource or in a willDisplayCell of UITableViewDelegate.

How Could I pass the selected Cell on UITableViewController with UIActionSheet

I have UITableViewController which pop UIActionSheet when user click on a cell with accessoryType =UITableViewCellAccessoryDetailDisclosureButton;
Now the method -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { works fine, except, i dont know in which cell user clicked.
I could , for example, declare a property where I save selected cell in didSelectRowAtIndexPath:(NSIndexPath *)indexPath { but I think there must be a better way.
I usually set the action sheet's tag to be the index path's row, but that only works if you don't care about the section number. If you do need the section as well, creating a property would be the best way to go about it.
You could also mess with a category and associated objects, but for me personally that would be too involved.
If your table only have one section, you could store which row presented the action sheet in the tag, something like this.
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSString *title = [NSString stringWithFormat:#"Sheet for row %i", indexPath.row];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Option 1", #"Option 2", nil];
[sheet setTag:indexPath.row];
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
int row = actionSheet.tag;
NSLog(#"Selected actionSheet buttonIndex %i for row: %i", buttonIndex, row);
}
It's probably the easiest way, but I wouldn't say it's the best way to do it.
Implement this UITableView delegate method to get the index path of the cell when the accessory button is tapped:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
}

DisclosureIndicator does not detect touches

I am using UITableViewCellAccessoryDisclosureIndicator as accessoryType of my UITableViewCell. According to Apple's documentation, the data source method
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
should automatically get called.
If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton, the accessory view tracks touches and, when tapped, sends the data-source object a tableView:accessoryButtonTappedForRowWithIndexPath: message.
here's my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[cell.textLabel setText:[datasource objectAtIndex:indexPath.row]];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
The data source method is just a NSLog but nothing is printed...
Am I missing something? (of course, data source and delegate are set properly)
The answer is in your question. You said
I am using UITableViewCellAccessoryDisclosureIndicator as
accessoryType ...
and you quoted the Apple docs in part
If the cell is enabled and the accessory type is UITableViewCellAccessoryDetailDisclosureButton ...
Only when you use UITableViewCellAccessoryDetailDisclosureButton is the delegate method called. The difference, of course, is that this is a button, where UITableViewCellAccesssoryDisclosureIndicator is not. When you use the latter, tapping it is like tapping the cell itself. You could create a custom cell and implement hitTest: to determine if the tap was "near" the disclosure indicator, but that seems like more work than necessary (unless you really don't want to use a detail disclosure button).
Check out the names of the accessory indicators UITableViewCellAccessoryNone, UITableViewCellAccessoryDisclosureIndicator, UITableViewCellAccessoryDetailDisclosureButton UITableViewCellAccessoryCheckmark, UITableViewCellAccessoryDetailButton
Only detail button and detail disclosure button receives taps and calls the method . U may use UIGestureRecognizer and a custom method .

Resources