I have tableViewController and RSS feeds loaded in the tableView. I want to implement "header like" cell (of type OrderCell.h/.m) with "order by date" and "order by popularity" custom 开发者_如何学JAVAbuttons that reorder rssItems array and refresh the table view when pressed.
How can I refresh the tableView from OrderCell object method? I have no problem reordering the rssItems array because I defined it as a static var with static methods available from outside the class TableViewController. My problem is calling [xxx.tableView reloadData]; when a user clicks a button "order by". Since OrderCell object is instantiated from TableViewController object how can I call the reload method of TableViewController object?
Thanks in advance, Luka
You could define your own protocol which will be implemented (Confirmed) by the TableViewController
class ,
In myTableClass.h
@protocol AppDelegate
-(void) OrderSelected ;
@end
@interface myTableClass : UITableViewController <AppDelegate>
{
.......
}
@end
In OrderCell.h
@interface OrderCell : .....
{
id<AppDelegate> myDelegate;
}
@property(nonatomic,assign) id<AppDelegate> myDelegate;;
@end
In OrderCell.cpp
@synthesize myDelegate;
-(void) myButtonAction:(id) sender
{
[myDelegate OrderSelected];
}
and
In myTableClass.cpp
When you create the OrderCell just write the Online Statement
myOrderCell.myDelegate = self;
and implement the protocol function
-(void) OrderSelected
{
[self.tableView reloadTable];
}
add delegate in you other class for you table view controller first and assign your current tableview controller to that delegate and in your table view controller add a method like
-(void) updateTableItems {
[self.table reloadData];
}
-(void) threadLoop {
[self performSelectorOnMainThread:@selector(updateTableItems) withObject:nil waitUntilDone:NO];
}
now using delegate of other class call threadLoop of your table view controller, good luck
精彩评论