Adding a button to TTTable View Item - iphone

I have been banging my head on adding a button to a cell. This is what I have done.
I subclassed TTTableMessageItem and TTTableMessageItemCell.
I added the following method to the Message Item init :
+ (id)itemWithTitle:(NSString *)title caption:(NSString *)caption text:(NSString *)text timestamp:(NSDate *)timestamp imageURL:(NSString *)imageURL URL:(NSString *)URL target:(id)target action:(SEL)action;
I also added a SEL variable and "id" for action and target.
Under setObject in message Item Cell I added this :
- (void)setObject:(id)object {
if (_item != object) {
[super setObject:object];
TJTableMessageItem* item = object;
if (item.plusAction) {
self.plusAction = item.plusAction;
}
if (item.plusTarget) {
self.plusTarget = item.plusTarget;
}
}
}
I am now able to trigger easily a method inside my datasource for the tableview. But I am not able to find out which cell was pressed. I hope someone can help me, I have spent way to much time figuring out the setObject part.
I would like to know how and add a subview like the Facebook app has, the Like, Comment part. I think I need to be able to run a method inside the view controller. But I can't find anything anywhere. The Cybersam blog has an explanation that doesn't use the TableItem and TableItemCell like Three20 puts things up.

assume that the target is your TableViewController, and the the SEL has an argument named sender, like this:
- (void)likeButtonClicked:(id)sender;
then you can find the Cell View according to sender (sender.superView.....), and use the TableView to find the cell's index, that's all.

Related

UITableView - (void)configureView

I'm working now with table views and detailed views, you know that one which appears when you select element in your table.
there is a method - (void)configureView which is called in viewDidLoad and descriptions say it updates interface.
I've got something like this:
- (void)configureView
{
// Update the user interface for the detail item.
if (self.detailItem) {
self.detailDescriptionLabel.text = self.detailItem;
}
if (self.subjectItem) {
self.subjectLabel.text = [self.subjectItem description];
}
self.imageView.image = self.imageItem;}
my question is: is "description" property required? because it works without it(the first item and imageView), and if so then how syntax would look like for imageView? because "description" is only for NSStrings
Really description is a method of NSObject: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html
You don't need to use it in your code above, neither for NSString.
Just be sure to assign to the properties the correct objects (i.e. self.imageItem must be an istance of UIImage).

How to determine which section header in UITableView is being edited

I have a UITextField in a custom section header. There are multiple sections using this style of header, and therefore multiple UITextFields.
I have implemented the UITextFieldDelegate. When I edit one of these UITextFields, it calls the delegate method textFieldDidEndEditing. How do I determine which section header this UITextField was in? I need to save the value to core data in the appropriate NSManagedObject for that section.
Many thanks in advance
EDIT: Several people have suggested using a tag of the section number when creating the cell, which would work perfectly. However, I have already assigned the UITextField a tag to distinguish it as a 'header' textfield as opposed to a cell textfield or a 'footer' textfield. There are a whole lotta textfields on this table!!
Further EDIT: Using in indexPath has been suggested. This would be my preferred solution if I can get it to work. Does anyone know if headers and footers have indexPaths?
You could use tags to identify UITextField instances. Since you're already setting tags in UITextField instances, set the tags on the section views itself:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *sectionView = ... // your section view instance
// assign the section index as the tag
sectionView.tag = section;
return sectionView;
}
In the textfield delegate, get the section index from the sender's parent:
- (void) textFieldDidEndEditing:(UITextField *)textField;
{
NSInteger theSectionIndex = textField.superview.tag;
// your custom logic here
}
You would probably want to look into UITableView method indexPathForCell:.
You can get the cell through view hierarchy from your UITextField, since it's in your Cell's contentView.
Regards,
sven.
It is very simple Mr.Ben Thompson. You have named different between each one to UITextFields am i right?. Just find the specific UITextField by used it's name.
-(void) textFieldDidEndEditing:(UITextField *)textField
{
if (textField == textfieldOne)
{
//Do whatever you want...
}
else if (textField == textfieldTwo)
{
//Do whatever you want...
}
else if (textField == textfieldThree)
{
//Do whatever you want...
}
}
I hope it will help you a little bit. Thanks.
i believe you add the field as a custom view to the header in viewForHeader method of tableview.
I suggest keeping a tag of the field using the section like this.
textfield.tag == section;
then in the delegate message you can have a switch method to compare tags..and do your own code there

Custom Detail Image View from Three20

I am pretty new with Three20. I have followed ray wenderlich's nice introduction to three20 and the examples within the three20 framework. When I click on a thumbnail in a thumbnail view (subclass of TTThumbsViewController) to launch a Details view, a standard Details image view (deployed by TTPhotoViewController or its super class). I would like to use my own implementation of a Details View instead of the default. I put the following code when I initiated the subclass of TTThumbsViewController and TTThumbsViewControllerDelegate method:
- (id)initWithDelegate:(id<TTThumbsViewControllerDelegate>)delegate {
[super initWithDelegate:delegate];
return self;
}
- (void)thumbsViewController: (TTThumbsViewController*)controller
didSelectPhoto: (id<TTPhoto>)photo {
[navigationController.pushViewController:photoDetailViewController
animated:Yes];
}
But the default TTPhotoViewController view still prevail. When I put a NSLog in the delegate method. I coud see the method was called. I think there is another delegate someone already set in TTThumViewController? Can someone recommend a way to display my detail photo view? Is there another thumbs view controller I can use? Any suggestion will be greatly appreciated.
I'm really new to all of this (coding, etc.) but I'll share what I've found. By looking up the definition of ttthumbsviewcontroller, I was able to find the following method(wrong term?):-
- (void)thumbsTableViewCell:(TTThumbsTableViewCell*)cell didSelectPhoto:(id<TTPhoto>)photo {
[_delegate thumbsViewController:self didSelectPhoto:photo];
BOOL shouldNavigate = YES;
if ([_delegate respondsToSelector:#selector(thumbsViewController:shouldNavigateToPhoto:)]) {
shouldNavigate = [_delegate thumbsViewController:self shouldNavigateToPhoto:photo];
}
if (shouldNavigate) {
NSString* URL = [self URLForPhoto:photo];
if (URL) {
TTOpenURLFromView(URL, self.view);
} else {
TTPhotoViewController* controller = [self createPhotoViewController];
controller.centerPhoto = photo;
[self.navigationController pushViewController:controller animated:YES];
}
}
}
In the else statement, I've found this calls the creation of the photoviewcontroller. By recalling this method (?) in the actual body of my own code and changing the body in the else statement I was able to add a custom detail view. Further down the definition of the ttthumbsnailviewcontroller, you can find that the creatPhotoViewController calls for an initiation of the PhotoViewController so calling that method(?) in the body of the code and initializing another view also works.
If someone can explain whether or not this is a good method of doing this (I have a feeling that is not), it would be appreciated. Also why does putting the method in the body of the code override the call there.

Passing a value on a IBAction button method in a UITableview Row

I have a value called member id and I want to send it to another view controller, If I place the following in didSelectRowAtIndexPath, The value passes to the variable "member".
int memberIndex = [indexPath indexAtPosition: [indexPath length] - 1];
member = [[tableDataSource2 objectAtIndex: memberIndex] objectForKey:#"Memberid"];
If it is placed in the cellForRow, of course it rewrites with every row created. I have a button in each row that launches a viewController, I want the button action to grab the rows "member" and pass it to the new controller. Is there a "didSelectButton at index path method" or a way to grab that on the fly?
any Ideas would be great. It's the first time I'm adding a button to a UiTableview.
Thanks
Why not use the accessory view? It is a built-in button that you can skin with any image you want to give the UI any kind of feel that is required. Then add this to the table's delegate:
accessoryButtonTappedForRowWithIndexPath: (NSIndexPath *) indexPath{ ... }
You will then be able to call your method on your table data source and launch your secondary view.
Just play with "tag".
Each UIView has an attribute tag (int).
in the cellForRowAtIndexPath :
//create yourButton and then
yourButton.tag = memberIndex;
and when you are using an IBAction just get the sender :
- (IBAction) didSelectButton:(id)sender
{
int memberIndex = ((UIButton *)sender).tag;
//
}
tips : to get the sender when you are setting the action property of your button don't forget the ":"
E.G
action = #selector(didSelectButton:);

tagging a cell for identification in a selected tableview

how is it possible to tag an iphone cell in order to be able to use in a selected favorite table view. i want to be able to tagg the cell and its remaining content in order to be able to display it properly inside a new table view under a different view controller.
You set a tag with a number and by looking at UIView class ref, you set it with an NSInteger,
so a number to you and me.
tableViewCell.tag = 1
Or you extend UITableView and add your own method like
- (void) setFavorite:(BOOL)ans
{
favorited = ans;
}
- (BOOL) favorite
{
return favorited;
}
And then when you access the table view cell, cast it.
Probably better to make it a property though
#property (nonatmoic, assign, getter=isFavorited) BOOL favorited;