29. UITableView
Creating your UITableView
UITableView *table;
table = [[UITableView alloc]
initWithFrame:self.view.bounds
style:UITableViewStylePlain];
Friday, 16 September 11
30. UITableView
Creating your UITableView
UITableView *table;
table = [[UITableView alloc]
initWithFrame:self.view.bounds
style:UITableViewStylePlain];
Setting up your delegates
table.delegate = self;
table.dataSource = self;
Friday, 16 September 11
31. UITableView
Creating your UITableView
UITableView *table;
table = [[UITableView alloc]
initWithFrame:self.view.bounds
style:UITableViewStylePlain];
Setting up your delegates
table.delegate = self;
table.dataSource = self;
Adding the table to the view
[self.view addSubview:table];
Friday, 16 September 11
41. UITableViewDataSource
How many sections do I have?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
Friday, 16 September 11
42. UITableViewDataSource
How many sections do I have?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
How many rows are in each section?
Friday, 16 September 11
43. UITableViewDataSource
How many sections do I have?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
How many rows are in each section?
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section;
Friday, 16 September 11
44. UITableViewDataSource
How many sections do I have?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
How many rows are in each section?
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section;
What is the cell for a given row/section?
Friday, 16 September 11
45. UITableViewDataSource
How many sections do I have?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
How many rows are in each section?
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section;
What is the cell for a given row/section?
- (UITableViewCell *)tableView:(UITableView *)aTableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Friday, 16 September 11
46. Demo 1:
Basic table view
Friday, 16 September 11
50. Customising Cells
if (cell == nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier] autorelease];
self.textLabel.backgroundColor = [UIColor clearColor];
self.textLabel.font = [UIFont boldSystemFontOfSize:14];
self.textLabel.shadowOffset = CGSizeMake(0, 1);
// And a whole lot more
}
Friday, 16 September 11
51. Customising Cells
if (cell == nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier] autorelease];
self.textLabel.backgroundColor = [UIColor clearColor];
self.textLabel.font = [UIFont boldSystemFontOfSize:14];
self.textLabel.shadowOffset = CGSizeMake(0, 1);
// And a whole lot more
}
Friday, 16 September 11
52. Customising Cells
if (cell == nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellIdentifier] autorelease];
self.textLabel.backgroundColor = [UIColor clearColor];
self.textLabel.font = [UIFont boldSystemFontOfSize:14];
self.textLabel.shadowOffset = CGSizeMake(0, 1);
// And a whole lot more
}
Refactor into our own styled cell class
Friday, 16 September 11
53. PropertyCell
A subclass of UITableViewcell
Friday, 16 September 11
54. PropertyCell
A subclass of UITableViewcell
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style
reuseIdentifier:reuseIdentifier]))
{
self.textLabel.textColor = [UIColor darkGrayColor];
self.textLabel.backgroundColor = [UIColor clearColor];
// More cell styling code goes here
}
return self;
}
Friday, 16 September 11
55. Demo 2:
Custom table view
Friday, 16 September 11
57. Backend server
• Hosted on Heroku
• http://rmit-property-search.heroku.com/search
• Written in Ruby
• Uses the Sinatra framework
Friday, 16 September 11
59. Server code
require 'rubygems'
require 'bundler'
require 'erb'
Bundler.require
get '/search' do
@search = params[:q]
erb :properties
end
Friday, 16 September 11
60. Server code
require 'rubygems'
require 'bundler'
require 'erb'
Bundler.require
get '/search' do
@search = params[:q] template
erb :properties
end JSON file
Friday, 16 September 11
88. UITableViewDelegate
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
• pull out the Property object for selected row
• create a new DetailViewController with that Property
• push the new controller onto the navigation stack
Friday, 16 September 11
89. Demo 4:
Master / Detail
Friday, 16 September 11
92. What’s missing?
• Can’t dismiss the keyboard
Friday, 16 September 11
93. What’s missing?
• Can’t dismiss the keyboard
• Search does not actually search
Friday, 16 September 11
94. What’s missing?
• Can’t dismiss the keyboard
• Search does not actually search
• No progress indicator while loading
Friday, 16 September 11
95. What’s missing?
• Can’t dismiss the keyboard
• Search does not actually search
• No progress indicator while loading
• People like pull-to-refresh like Facebook
Friday, 16 September 11
96. Demo 5:
Making it awesome
Friday, 16 September 11