SlideShare una empresa de Scribd logo
1 de 22
Table Views
IOS Application Development Series
About Table Views
• UI Component that presents data in scrollable
list.
Holds rows that may divided into sections
• Many purposes
– Navigate data
– Present data
– Selectable list of opFons
• Two styles: plain or grouped
Plain Table View
Grouped Table View
Table Views and Table View Cells
• A table view is the view object that displays a table’s data and is an
instance of the class UITableView.
• Each visible row of the table is implemented by the class
UITableViewCell.
• So, a table view is the object that displays the visible part of a
table, and a table view cell is responsible for displaying a single row
of the table
UITableViewCell
• Each UITableViewCell object can be configured
with an image, some text, and an optional
accessory icon, which is a small icon on the
right side
UITableViewDataSource Protocol
• The UITableViewDataSource protocol is adopted by an object that
mediates the application’s data model for a UITableView object.
• The data source provides the table-view object with the
information it needs to construct and modify a table view.
• As a representative of the data model, the data source supplies
minimal information about the table view’s appearance
• The table-view object’s delegate—an object adopting the
UITableViewDelegate protocol—provides that information.
• The required methods of the protocol provide the cells to be
displayed by the table-view as well as inform the UITableView
object about the number of sections and the number of rows in
each section.
• The data source may implement optional methods to configure
various aspects of the table view and to insert, delete, and reorder
rows.
UITableViewDataSource required
instance methods
• 1. tableView:cellForRowAtIndexPath:
• This methods asks the data source for a cell to insert it in a particular
location in the table view. Syntax for method isgiven by:
• - (UITableViewCell *)tableView:(UITableView
*)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath
• Parameters: 1.tableView A table-view object requesting the cell.
2.indexPath An index path locating a row in tableView.
• Return Value:Anobject inheriting from UITableViewCell that the table view
can use for the specified row. An assertion is raised if you return nil.
• Discussion: The returned UITableViewCell object is frequently one that the
application reuses for performance reasons. You should fetch a previously
created cell object that is marked for reuse by sending a
dequeueReusableCellWithIdentifier: message to tableView. Various
attributes of a table cell are set automatically based on whether the cell is
a separator and on information the data source provides, such as for
accessory views and editing controls.
UITableViewDataSource required
instance methods
UITableViewDelegate Protocol
• The delegate of a UITableView object must
adopt the UITableViewDelegate protocol.
Optional methods of the protocol allow the
delegate to manage selections, configure
section headings and footers, help to delete
and reorder cells, and perform other actions.
Frequently used Methods
Creating a Table View Application
•
•
•

Create empty Application
Set root view controller
Add these protocols to BIDTableViewController.h<UITableViewDataSource,
UITableViewDelegate>
• Drag Table View to the view from Object Library
• Connect Table View With File Owner
• Connect delegate and data source with File owner from Connection Inspector
• Create and Array
• Initiate array in viewDidLoad method in BIDTableViewController.m file
• add Method: - (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
• Add Method: - (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
Explaining the Methods
•
•
•
•
•

•

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
This method is called by the table view when it needs to draw one of its rows.
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"
This string will be used as a key to represent the type of our table cell. Our table
will use only a single type of cell.
A table view can display only a few rows at a time on the iPhone’s small
screen, but the table itself can conceivably hold considerably more. Remember
that each row in the table is represented by an instance of UITableViewCell, a
subclass of UIView, which means each row can contain subviews. With a large
table, this could represent a huge amount of overhead if the table were to try to
keep one table view cell instance for every row in the table, regardless of whether
that row was currently being displayed.
Instead, as table view cells scroll off the screen, they are placed into a queue of
cells available to be reused. If the system runs low on memory, the table view will
get rid of the cells in the queue. But as long as the system has some memory
available for those cells, it will hold on to them in case you want to use them again.
Explaining the Methods
•

•
•

•

Every time a table view cell rolls off the screen, there’s a pretty good chance that
another one just rolled onto the screen on the other side. If that new row can just
reuse one of the cells that has already rolled off the screen, the system can avoid
the overhead associated with constantly creating and releasing those views. To
take advantage of this mechanism, we’ll ask the table view to give us a previously
used cell of the specified type. Note that we’re making use of the NSString
identifier we declared earlier. In effect, we’re asking for a reusable cell of type
SimpleTableIdentifier.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SimpleTableIdentifier];
Now, it’s completely possible that the table view won’t have any spare cells (when
it’s being initially populated, for example), so we check cell after the call to see
whether it’s nil. If it is, we manually create a new table view cell using that
identifier string. At some point, we’ll inevitably reuse one of the cells we create
here, so we need to make sure that we create it using SimpleTableIdentifier.
if (cell == nil) { cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier];
}
Displaying Data in UITableViewCell
• We now have a table view cell that we can return for the table view to use.
So, all we need to do is place whatever information we want displayed in
this cell. Displaying text in a row of a table is a very common task, so the
table view cell provides a UILabel property called textLabel that we can set
in order to display strings. That just requires getting the correct string from
our listData array and using it to set the cell’s textLabel.
• To get the correct value, however, we need to know which row the table
view is asking for. We get that information from the indexPath's row
property. We use the row number of the table to get the corresponding
string from the array, assign it to the cell’s textLabel.text property, and
then return the cell.
• To get the correct value, however, we need to know which row the table
view is asking for. We get that information from the indexPath's row
property. We use the row number of the table to get the corresponding
string from the array, assign it to the cell’s textLabel.text property, and
then return the cell.
• cell.textLabel.text = self.dwarves[indexPath.row]; return cell;
Adding an Image
• Each cell has an imageView property.
• Each imageView has an image property, as well as a highlightedImage
property. The image appears to the left of the cell’s text and is replaced by
the highlightedImage, if one is provided, when the cell is selected.
• You just set the cell’s imageView.image property to whatever image you
want to display.
• Add following code in- (UITableViewCell *)tableView:(UITableView
*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathmethohd ,
the code is :
• Adding Normal image:
• UIImage *image = [UIImage imageNamed:@"normal.png"];
• cell.imageView.image = image;
• Adding highlighted image:
• UIImage *image = [UIImage imageNamed:@"highlighted.png"];
Choosing Accessory Type
• Add following code in same function:
• cell.accessoryType =
UITableViewCellAccessoryDisclosureIndicator
;
• You Can also give custom image to the
accessorindicator.To do so add follwing code.
• cell.accessoryView = [[UIImageViewalloc]
initWithImage:[UIImageimageNamed:@"disc
.png"]];
Changing Background Color of the
Selected Cell
• To change the background color of a selected
Cell we do so.
• UIView *selectedBackgroundViewForCell =
[UIView new];
[selectedBackgroundViewForCellsetBackgrou
ndColor:[UIColorblackColor]];
cell.selectedBackgroundView
=selectedBackgroundViewForCell;
Changing Font Colors and Font style
and Font Size
•
•
•
•

Setting Text color for cell Text Label
cell.textLabel.textColor=[UIColorblackColor];
Setting Text color when cell is selected
cell.textLabel.highlightedTextColor =
[UIColorwhiteColor];
• setting font and text size
• cell.textLabel.font =
[UIFontfontWithName:@"Times New Roman"
size:18.0f];
Setting Table View Background Color
• Make an Outlet of Table and Connect it with the
table in interface Builder.
• Synthesize the table outlet
• First set cell color to clear color as in order to
enable table background color work.
• Cell.backgroundcolor=[UIColorclearColor];
• Then in viewDidLoadMethod add follwing code
• [table setBackgroundColor:[UIColor
colorWithRed:(255/255.0) green:(193/255.0)
blue:(37/255.0) alpha:1]]
Setting Row Height of the Table View
Cell
• We have a special method to accomplish this task
• Add this method to BIDTableViewcontroller.mfile
• Add the following code which includes method and
expected row height.
• - (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
Setting indent Level
• We again have a special method to add indent
level to each row of UITableView.
• Method and Code is given by. Add in same class
as did in last slide
• -(NSInteger)tableView:(UITableView
*)tableViewindentationLevelForRowAtIndexPat
h:(NSIndexPath *)indexPath
{
return indexPath.row;
}

Más contenido relacionado

La actualidad más candente

La actualidad más candente (6)

Mysql Optimization
Mysql OptimizationMysql Optimization
Mysql Optimization
 
Session 2 django material for training at baabtra models
Session 2 django material for training at baabtra modelsSession 2 django material for training at baabtra models
Session 2 django material for training at baabtra models
 
30 08 Final Sql
30 08 Final Sql30 08 Final Sql
30 08 Final Sql
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
 
Comilla University
Comilla University Comilla University
Comilla University
 
Vtiger picklist 创建实例
Vtiger picklist 创建实例Vtiger picklist 创建实例
Vtiger picklist 创建实例
 

Destacado

COMPLETE SOLUTION OF ADVERTISEMENT
COMPLETE SOLUTION OF ADVERTISEMENTCOMPLETE SOLUTION OF ADVERTISEMENT
COMPLETE SOLUTION OF ADVERTISEMENTSatyendra Gupta
 
Economics reviewer
Economics reviewerEconomics reviewer
Economics reviewerBelle Gamboa
 
Ang modernong pananaw ng mga kabataan
Ang modernong pananaw ng mga kabataanAng modernong pananaw ng mga kabataan
Ang modernong pananaw ng mga kabataanAudie Judalena
 
signages and complete solution of advertise
signages and complete solution of advertise signages and complete solution of advertise
signages and complete solution of advertise Satyendra Gupta
 
Teaching Money With Techonology
Teaching Money With TechonologyTeaching Money With Techonology
Teaching Money With TechonologyAmandaCianciola
 
Virtual Reality Museums
Virtual Reality MuseumsVirtual Reality Museums
Virtual Reality MuseumsMattia Crespi
 
signages . sign boards , designing , advertisement,
signages . sign boards , designing , advertisement,signages . sign boards , designing , advertisement,
signages . sign boards , designing , advertisement,Satyendra Gupta
 

Destacado (10)

COMPLETE SOLUTION OF ADVERTISEMENT
COMPLETE SOLUTION OF ADVERTISEMENTCOMPLETE SOLUTION OF ADVERTISEMENT
COMPLETE SOLUTION OF ADVERTISEMENT
 
Economics reviewer
Economics reviewerEconomics reviewer
Economics reviewer
 
Ferdinand E. Marcos
Ferdinand E. MarcosFerdinand E. Marcos
Ferdinand E. Marcos
 
Ang modernong pananaw ng mga kabataan
Ang modernong pananaw ng mga kabataanAng modernong pananaw ng mga kabataan
Ang modernong pananaw ng mga kabataan
 
Electronic cigarette
Electronic cigaretteElectronic cigarette
Electronic cigarette
 
whatever it takes
 whatever it takes whatever it takes
whatever it takes
 
signages and complete solution of advertise
signages and complete solution of advertise signages and complete solution of advertise
signages and complete solution of advertise
 
Teaching Money With Techonology
Teaching Money With TechonologyTeaching Money With Techonology
Teaching Money With Techonology
 
Virtual Reality Museums
Virtual Reality MuseumsVirtual Reality Museums
Virtual Reality Museums
 
signages . sign boards , designing , advertisement,
signages . sign boards , designing , advertisement,signages . sign boards , designing , advertisement,
signages . sign boards , designing , advertisement,
 

Similar a Table views

Swift Tableview iOS App Development
Swift Tableview iOS App DevelopmentSwift Tableview iOS App Development
Swift Tableview iOS App DevelopmentKetan Raval
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search barVu Tran Lam
 
Table views
Table viewsTable views
Table viewsSV.CO
 
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersCocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersStijn Willems
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Michael Shrove
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)Ehtisham Ali
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14Sisir Ghosh
 
아이폰강의(6) pdf
아이폰강의(6) pdf아이폰강의(6) pdf
아이폰강의(6) pdfsunwooindia
 
Introducing collection views - Mark Pospesel
Introducing collection views - Mark PospeselIntroducing collection views - Mark Pospesel
Introducing collection views - Mark PospeselJigar Maheshwari
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptxMohamedNowfeek1
 
아이폰강의(4) pdf
아이폰강의(4) pdf아이폰강의(4) pdf
아이폰강의(4) pdfsunwooindia
 
Using a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS appsUsing a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS appsallanh0526
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)Katy Slemon
 

Similar a Table views (20)

Swift Tableview iOS App Development
Swift Tableview iOS App DevelopmentSwift Tableview iOS App Development
Swift Tableview iOS App Development
 
iOS: Table Views
iOS: Table ViewsiOS: Table Views
iOS: Table Views
 
Session 14 - Working with table view and search bar
Session 14 - Working with table view and search barSession 14 - Working with table view and search bar
Session 14 - Working with table view and search bar
 
занятие7
занятие7занятие7
занятие7
 
Table views
Table viewsTable views
Table views
 
Cocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollersCocoa heads testing and viewcontrollers
Cocoa heads testing and viewcontrollers
 
Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)Android and IOS UI Development (Android 5.0 and iOS 9.0)
Android and IOS UI Development (Android 5.0 and iOS 9.0)
 
201104 iphone navigation-based apps
201104 iphone navigation-based apps201104 iphone navigation-based apps
201104 iphone navigation-based apps
 
IOS Storyboards
IOS StoryboardsIOS Storyboards
IOS Storyboards
 
Sql server ___________session_16(views)
Sql server  ___________session_16(views)Sql server  ___________session_16(views)
Sql server ___________session_16(views)
 
ASP.NET Session 13 14
ASP.NET Session 13 14ASP.NET Session 13 14
ASP.NET Session 13 14
 
아이폰강의(6) pdf
아이폰강의(6) pdf아이폰강의(6) pdf
아이폰강의(6) pdf
 
Introducing collection views - Mark Pospesel
Introducing collection views - Mark PospeselIntroducing collection views - Mark Pospesel
Introducing collection views - Mark Pospesel
 
Vertica-Database
Vertica-DatabaseVertica-Database
Vertica-Database
 
Collections Training
Collections TrainingCollections Training
Collections Training
 
05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx05 Create and Maintain Databases and Tables.pptx
05 Create and Maintain Databases and Tables.pptx
 
아이폰강의(4) pdf
아이폰강의(4) pdf아이폰강의(4) pdf
아이폰강의(4) pdf
 
Using a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS appsUsing a model view-view model architecture for iOS apps
Using a model view-view model architecture for iOS apps
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
I os 04
I os 04I os 04
I os 04
 

Último

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 

Último (20)

What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 

Table views

  • 1. Table Views IOS Application Development Series
  • 2. About Table Views • UI Component that presents data in scrollable list. Holds rows that may divided into sections • Many purposes – Navigate data – Present data – Selectable list of opFons • Two styles: plain or grouped
  • 5. Table Views and Table View Cells • A table view is the view object that displays a table’s data and is an instance of the class UITableView. • Each visible row of the table is implemented by the class UITableViewCell. • So, a table view is the object that displays the visible part of a table, and a table view cell is responsible for displaying a single row of the table
  • 6. UITableViewCell • Each UITableViewCell object can be configured with an image, some text, and an optional accessory icon, which is a small icon on the right side
  • 7. UITableViewDataSource Protocol • The UITableViewDataSource protocol is adopted by an object that mediates the application’s data model for a UITableView object. • The data source provides the table-view object with the information it needs to construct and modify a table view. • As a representative of the data model, the data source supplies minimal information about the table view’s appearance • The table-view object’s delegate—an object adopting the UITableViewDelegate protocol—provides that information. • The required methods of the protocol provide the cells to be displayed by the table-view as well as inform the UITableView object about the number of sections and the number of rows in each section. • The data source may implement optional methods to configure various aspects of the table view and to insert, delete, and reorder rows.
  • 8. UITableViewDataSource required instance methods • 1. tableView:cellForRowAtIndexPath: • This methods asks the data source for a cell to insert it in a particular location in the table view. Syntax for method isgiven by: • - (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath • Parameters: 1.tableView A table-view object requesting the cell. 2.indexPath An index path locating a row in tableView. • Return Value:Anobject inheriting from UITableViewCell that the table view can use for the specified row. An assertion is raised if you return nil. • Discussion: The returned UITableViewCell object is frequently one that the application reuses for performance reasons. You should fetch a previously created cell object that is marked for reuse by sending a dequeueReusableCellWithIdentifier: message to tableView. Various attributes of a table cell are set automatically based on whether the cell is a separator and on information the data source provides, such as for accessory views and editing controls.
  • 10. UITableViewDelegate Protocol • The delegate of a UITableView object must adopt the UITableViewDelegate protocol. Optional methods of the protocol allow the delegate to manage selections, configure section headings and footers, help to delete and reorder cells, and perform other actions.
  • 12. Creating a Table View Application • • • Create empty Application Set root view controller Add these protocols to BIDTableViewController.h<UITableViewDataSource, UITableViewDelegate> • Drag Table View to the view from Object Library • Connect Table View With File Owner • Connect delegate and data source with File owner from Connection Inspector • Create and Array • Initiate array in viewDidLoad method in BIDTableViewController.m file • add Method: - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section • Add Method: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  • 13. Explaining the Methods • • • • • • - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath This method is called by the table view when it needs to draw one of its rows. static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier" This string will be used as a key to represent the type of our table cell. Our table will use only a single type of cell. A table view can display only a few rows at a time on the iPhone’s small screen, but the table itself can conceivably hold considerably more. Remember that each row in the table is represented by an instance of UITableViewCell, a subclass of UIView, which means each row can contain subviews. With a large table, this could represent a huge amount of overhead if the table were to try to keep one table view cell instance for every row in the table, regardless of whether that row was currently being displayed. Instead, as table view cells scroll off the screen, they are placed into a queue of cells available to be reused. If the system runs low on memory, the table view will get rid of the cells in the queue. But as long as the system has some memory available for those cells, it will hold on to them in case you want to use them again.
  • 14. Explaining the Methods • • • • Every time a table view cell rolls off the screen, there’s a pretty good chance that another one just rolled onto the screen on the other side. If that new row can just reuse one of the cells that has already rolled off the screen, the system can avoid the overhead associated with constantly creating and releasing those views. To take advantage of this mechanism, we’ll ask the table view to give us a previously used cell of the specified type. Note that we’re making use of the NSString identifier we declared earlier. In effect, we’re asking for a reusable cell of type SimpleTableIdentifier. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; Now, it’s completely possible that the table view won’t have any spare cells (when it’s being initially populated, for example), so we check cell after the call to see whether it’s nil. If it is, we manually create a new table view cell using that identifier string. At some point, we’ll inevitably reuse one of the cells we create here, so we need to make sure that we create it using SimpleTableIdentifier. if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier]; }
  • 15. Displaying Data in UITableViewCell • We now have a table view cell that we can return for the table view to use. So, all we need to do is place whatever information we want displayed in this cell. Displaying text in a row of a table is a very common task, so the table view cell provides a UILabel property called textLabel that we can set in order to display strings. That just requires getting the correct string from our listData array and using it to set the cell’s textLabel. • To get the correct value, however, we need to know which row the table view is asking for. We get that information from the indexPath's row property. We use the row number of the table to get the corresponding string from the array, assign it to the cell’s textLabel.text property, and then return the cell. • To get the correct value, however, we need to know which row the table view is asking for. We get that information from the indexPath's row property. We use the row number of the table to get the corresponding string from the array, assign it to the cell’s textLabel.text property, and then return the cell. • cell.textLabel.text = self.dwarves[indexPath.row]; return cell;
  • 16. Adding an Image • Each cell has an imageView property. • Each imageView has an image property, as well as a highlightedImage property. The image appears to the left of the cell’s text and is replaced by the highlightedImage, if one is provided, when the cell is selected. • You just set the cell’s imageView.image property to whatever image you want to display. • Add following code in- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathmethohd , the code is : • Adding Normal image: • UIImage *image = [UIImage imageNamed:@"normal.png"]; • cell.imageView.image = image; • Adding highlighted image: • UIImage *image = [UIImage imageNamed:@"highlighted.png"];
  • 17. Choosing Accessory Type • Add following code in same function: • cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator ; • You Can also give custom image to the accessorindicator.To do so add follwing code. • cell.accessoryView = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"disc .png"]];
  • 18. Changing Background Color of the Selected Cell • To change the background color of a selected Cell we do so. • UIView *selectedBackgroundViewForCell = [UIView new]; [selectedBackgroundViewForCellsetBackgrou ndColor:[UIColorblackColor]]; cell.selectedBackgroundView =selectedBackgroundViewForCell;
  • 19. Changing Font Colors and Font style and Font Size • • • • Setting Text color for cell Text Label cell.textLabel.textColor=[UIColorblackColor]; Setting Text color when cell is selected cell.textLabel.highlightedTextColor = [UIColorwhiteColor]; • setting font and text size • cell.textLabel.font = [UIFontfontWithName:@"Times New Roman" size:18.0f];
  • 20. Setting Table View Background Color • Make an Outlet of Table and Connect it with the table in interface Builder. • Synthesize the table outlet • First set cell color to clear color as in order to enable table background color work. • Cell.backgroundcolor=[UIColorclearColor]; • Then in viewDidLoadMethod add follwing code • [table setBackgroundColor:[UIColor colorWithRed:(255/255.0) green:(193/255.0) blue:(37/255.0) alpha:1]]
  • 21. Setting Row Height of the Table View Cell • We have a special method to accomplish this task • Add this method to BIDTableViewcontroller.mfile • Add the following code which includes method and expected row height. • - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 70; }
  • 22. Setting indent Level • We again have a special method to add indent level to each row of UITableView. • Method and Code is given by. Add in same class as did in last slide • -(NSInteger)tableView:(UITableView *)tableViewindentationLevelForRowAtIndexPat h:(NSIndexPath *)indexPath { return indexPath.row; }