iphone - Multiple TableViews in a single screen -
I have a UIViewController, in which I am planning to place two table views and some other items. Both table views I am using on other screens, so I want to make them free and reusable. One of those table views is called Message List (A UTableView) which shows my chat history.
I am trying to understand what my attitude is [edit this code with correct code to work on this approach]
One approach is to separate 2 different sections To use a table, then use a conditional statement in representative methods and act accordingly.
Problems with this approach are applicability. I want to reuse my table scenes easily in other scenes, where one or the other tableview is in existence or not. Apart from this, I want Datacource to be present in the entire life cycle of the app even though the controller is being urgent or active.
My view is to separate the visual controller that manages the table view from the UITableViewDataSource and UITableViewDelegate implementations. But I'm having trouble doing this work.
The focus is on one of the table scenes, my ChatTab View
There is a property for chat in my appelaget. UITableViewDataSource
// AppDelegate.h
ChatHistory * chatHistory; ... @property (nontomic, retten) chatchiphone * chat history; // ChatHistory.h #import & lt; Foundation / Foundation. H & gt; @interface chat history: NSOJs & lt; UITableViewDelegate, UITableViewDataSource & gt; {UITableViewCell * nibLoadedCell; NSMutableArray * Message; } @property (nontomic, raten) UITableViewCell * nibLoadedCell; @property (nonatomic, retain) NSMutableArray * Message; @end // ChatHistory.m - Note this code, the custom cell was also working properly, when it was a part of the controller, I believe that this is correct Should be
#import "ChatHistory.h" #included "ChatMessage.h" @ implementation of ChatHistory @ synthesis nibLoadedCell; // custom cell design @ synthesis message; - (NSInteger) numberOfSectionsInTableView: (UITableView *) tableview {return1; } - (NSInteger) TableView: (UITableView *) table view numberoffrose insubstation: (NSInteger) section {return [number of messages]; } - (NSString *) Table View: (UITableView *) Table View Title ForHeaderInSection: (NSInteger) section {return [NSString stringWithFormat: @ "discussion"]; } - (UITableViewCell *) TableView: (UITableView *) Table View CellForAindindpath: (NSIndexPath *) Index Path {Fixed NSString * CellIdentifier = @ "cell"; UITableViewCell * cell = [tableview] dequeueReusableCellWithIdentifier: CellIdentifier]; If (cell == blue) {[[NSBindal main bundle] LodnIB nominated: @ "Chattableel" owner: self choice: zero]; Cell = nibbled cell; } // custom tag order - user name; message; Future - Avatar; like; Disliked Chat Message * obj = [Message ObjectAutandx: IndexPath.ro]; UILBL * MessageLabel = (UILb *) [cell viewtag: 1]; MessageLabel.text = obj.message; UILBL * User Name = Label (UILabel *) [Cell View Details: 2]; UsernameLabel.text = obj.sender; Return cell; } - (zero) DLOK {if (message) [message release]; [Super DeLoc]; } @end // MyViewController.m
- (zero) be sure to view viewDidLoad {// INITIALIZEDidoad NotInitWithNib if (! App Delegate.chatHistory) AppDelegate.chatHistory = [[Chat History Elliot] init]; MessageList = [[UITableView alloc] initWithFrame: CGRectMake (0, 54, 320, 100) style: UITableViewStylePlain]; MessageList.dataSource = appDelegate.chatHistory; MessageList.delegate = appDelegate.chatHistory; [Self.view addSubview: messageList]; ...
If you want a central data archive, Classes can create statistics. Then set it as a data source or get array (or whatever) to view your data in data from the UITableViewController / UITableViewController . If you initialize the data store in your AppDelegate , you can access it from every category (note that all the data you load, in iOS Will remain in your memory till the end)
Comments
Post a Comment