iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

iOS: Table Views and Navigation Controllers

Table Views Navigation Controllers Advanced TableViews

Tommy MacWilliam Harvard University

April 5, 2011

Announcements iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

Lectures: http://cs76.net/Lectures

I

Sections: http://cs76.net/Sections

Today iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

Property Lists

I

Table Views

I

Navigation Controllers

I

Advanced TableViews

plist iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views

I

key-value pairs, used to store settings

Navigation Controllers

I

XCode plist editor

Advanced TableViews

I

stored as XML

plist iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

name

I

NSString:



I

NSNumber:

,

I

NSDate:



I

NSData:



I

NSArray:

I

NSDictionary:

Table Views Navigation Controllers Advanced TableViews



plist iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

NSDictionary also contains key/value pairs

I

initWithContentsOfFile parses plist into an NSDictionary

I

writeToFile writes plist from NSDictionary

plist iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

NSBundle: location of resources in filesystem

I

mainBundle: bundle for current app

I

pathForResource:ofType: NSString of path to file of given type

TableViews iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

single-column tables, just like ListAdapters

I

bind data source (model) to UI (view)

I

UITableViewDataSource protocol I

or, just use the UITableViewController

TableViews iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

numberOfSectionsInTableView: define how many sections the table has

I

tableView:numberOfRowsInSection: define how many rows the table has

Table Views Navigation Controllers

I

Advanced TableViews

I

count of the model effectively ignore section if you just have one

I

tableView:cellForRowAtIndexPath: how to render a given cell

I

tableView:didSelectRowAtIndexPath: handle tap on a cell

cellForRowAtIndexPath iOS: Table Views and Navigation Controllers

I

Tommy MacWilliam

I

Property Lists Table Views

just as with Adapters, we want to recycle/cache cells to improve performance

I

Navigation Controllers Advanced TableViews

cell identifier: unique string identifying the type of cell we want I

I

cell off-screen: we can re-use it

more pertinent when using different types of cells in a table

dequeueReusableCellWithIdentifier: try to retrieve cell from the cache I I

nothing in the cache until user scrolls! if nil, nothing in cache, so create new cell

NSIndexPath iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views

I

I

Navigation Controllers Advanced TableViews

contains property for section and row

I

integer, 0-indexed

does NOT contain cell itself! I

[model objectAtIndex:indexPath.row];

Cell Properties iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers

I

cell.textLabel.text: text displayed in cell

I

cell.accessoryType: image at right of row, describes cell behavior I

Advanced TableViews

I

I

UITableViewCellAccessory DisclosureIndicator: chevron, designates drill-down UITableViewCellAccessory DetailDisclosureButton: blue arrow button, designates detail view UITableViewCellAccessory Checkmark: checkmark when row is selected

TableView Properties and Outlets iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

style attribute

Table Views

I

Navigation Controllers

I

Advanced TableViews

I

Plain: edge to edge rows Grouped: centered with rounded corners

outlets I

dataSource/delegate: where methods defining table behavior are defined

Setting up a TableView iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

example time!

UINavigationController iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

maintains a stack of view controllers

I

pushViewController:animated: push a new controller onto the stack and switch to it

I

popViewControlerAnimated: pop a view controller off the stack and switch to parent

Table Views Navigation Controllers Advanced TableViews

UIViewController Properties iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

self.navigationController: navigation controller managing the current stack

I

self.navigationItem: navigation bar for current view controller

Table Views Navigation Controllers Advanced TableViews

I I

title: text in navigation bar leftBarButton, rightBarButton: buttons on navigation bar

Pushing a new ViewController iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

don’t forget about @class (interface) and #import (implementation)! I

can’t access classes you’ve created without them

Pushing a new ViewController iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

from Interface Builder

Table Views Navigation Controllers Advanced TableViews

I I I I I

create outlet in interface add a generic View Controller object set class in Identity Inspector set nib name in Attributes Inspector connect View Controller to File’s Owner

Pushing a new ViewController iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

from Objective-C

Table Views Navigation Controllers

I

Advanced TableViews

alloc and initWithNibName: new instance of the controller I

I

no file extension on the nib

don’t forget to release!

UIImageView iOS: Table Views and Navigation Controllers

I

Tommy MacWilliam

image property of UIImageView changes UIImage displayed I

Property Lists Table Views Navigation Controllers Advanced TableViews

I

UIImage imageNamed: create UIImage from filename

contentMode property of UIImage controls how image is scaled I

I

I

UIViewContentModeScaleToFill: scale to fit, changing aspect ratio UIViewContentModeScaleAspectFit: scale to fit, maintaining aspect ratio UIViewContentModeScaleAspectFill: scale to fit, cropping if necessary

UIWebView iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views

I

loadRequest: load web page from NSURLRequest

Navigation Controllers

I

Advanced TableViews

I

NSURLRequest requestWithURL: create NSURLRequest from NSURL NSURL URLWithString: create NSURL from NSString

Navigation Controllers iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

example time!

TableView Sections iOS: Table Views and Navigation Controllers Tommy MacWilliam

I

can have different number of rows per section

Property Lists

I

Table Views Navigation Controllers Advanced TableViews

remember, numberInRowsInSection: gives the section as a parameter

I

titleForHeaderInSection: NSString of section header

I

titleForFooterInSection: NSString of section footer

TableView Sections iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

example time!

Editable TableViews iOS: Table Views and Navigation Controllers Tommy MacWilliam

I

self.editItemButton: built-in button handling delete/move

I

canEditRowAtIndexPath: set whether a given row is editable

Property Lists Table Views Navigation Controllers Advanced TableViews

I

I

return YES makes entire table editable

canMoveRowAtIndexPath: set whether a given row is movable

Editable TableViews iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists

I

commitEditingStyle:forRowAtIndexPath: edit operation performed on given row

I

moveRowAtIndexPath:toIndexPath: move operation performed on rows

I

update both model and view!

Table Views Navigation Controllers Advanced TableViews

I

invalidate state can lead to app crash

Editable TableViews iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

example time!

Cell Styles iOS: Table Views and Navigation Controllers Tommy MacWilliam

I Property Lists Table Views Navigation Controllers Advanced TableViews

notice the constructor for cells is initWithStyle: I I

I

I

UITableViewCellStyleDefault: no detail label UITableViewCellStyleSubtitle: detail label below UITableViewCellStyleValue1: detail label to the right UITableViewCellStyleValue2: equally-sized text and detail labels

Cell Styles iOS: Table Views and Navigation Controllers Tommy MacWilliam Property Lists Table Views Navigation Controllers Advanced TableViews

I

example time!

iOS: Table Views and Navigation Controllers - Tommy MacWilliam

Apr 5, 2011 - cell identifier: unique string identifying the type of cell we want. ▷ more pertinent when using different types of cells in a table ... Advanced. TableViews. NSIndexPath. ▷ contains property for section and row. ▷ integer, 0-indexed. ▷ does NOT contain cell itself! ▷ [model objectAtIndex:indexPath.row]; ...

89KB Sizes 1 Downloads 166 Views

Recommend Documents

iOS: Table Views and Navigation Controllers - Tommy MacWilliam
Apr 5, 2011 - iOS: Table. Views and. Navigation. Controllers. Tommy. MacWilliam. Property Lists. Table Views. Navigation. Controllers. Advanced. TableViews plist. ▷ key-value pairs, used to store settings. ▷ XCode plist editor. ▷ stored as XML 

Building MVC Web Applications - Tommy MacWilliam
Feb 15, 2012 - Controllers. Assets. TwitterNiter. Documentation. ▷ http://codeigniter.com/user_guide/ · database/active_record.html. ▷ your new best friend.

Building MVC Web Applications - Tommy MacWilliam
Feb 15, 2012 - Assets. TwitterNiter. Tweet Model. ▷ tweets table, each row is a tweet. ▷ tweets table has a Tweet model in application/models/tweet.php ...

Rewriting queries using views with negation - IOS Press
AI Communications 19 (2006) 229–237. 229. IOS Press. Rewriting queries using views with negation. Foto Afrati and Vassia Pavlaki. Department of Electrical ...

newS anD viewS - Nature
Jul 7, 2008 - possibly breast cancers4,5. However, in most advanced tumors, the response to antian- giogenic therapy, even in combination with conventional chemotherapy6, is not long lasting, and tumor cells bypass targeted sig- naling pathways and r

news and views
of capture DNA. The authors use this platform to study the ... riboswitch platforms represent important analytical approaches to metabolic engineer- ing and ...

Tommy John Surgery.pdf
Whoops! There was a problem loading more pages. Retrying... Tommy John Surgery.pdf. Tommy John Surgery.pdf. Open. Extract. Open with. Sign In.

Programmable Controllers
Due to the nature of this publication and because of the different applications of programmable controllers, the readers or users and those responsible for ...

Controllers & CPLD.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Controllers ...