Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 18, 2010, 07:36 AM   #1
mikezang
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
How can I know which TableView?

I have two TableView in a TableViewController as below, how can I know which TableView in cellForRowAtIndexPath?

Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *CustomCellIdentifier = @"CustomCellIdentifier ";
	
	CustomCell *cell = (CustomCell *)[tableView	dequeueReusableCellWithIdentifier:CustomCellIdentifier];
	
	if (cell == nil) {
		NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
		
		for (id oneObject in nib) {
			if ([oneObject isKindOfClass:[CustomCell class]]) {
				cell = (CustomCell *)oneObject;
			}
		}
	}

	NSUInteger row = [indexPath row];
	NSDictionary *rowData = [self.computers objectAtIndex:row];
	cell.colorLabel.text = [rowData objectForKey:@"Color"];
	cell.nameLabel.text = [rowData objectForKey:@"Name"];
						
	return cell;
}
Attached Thumbnails
Click image for larger version

Name:	SnapShot 2010-07-18 at 21.34.34.jpg
Views:	9
Size:	43.0 KB
ID:	239695  
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 07:38 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
The first parameter to the method is a pointe to the table view calling the method. Compare this pointer with the IBOutlet pointer you have to the tables you created in IB. If you do not have outlets linked to the two table views create some.
robbieduncan is offline   0 Reply With Quote
Old Jul 18, 2010, 07:56 AM   #3
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
I am sorry that I don"t what I can do, can you help me in more detail?
Attached Files
File Type: zip Archive.zip (24.2 KB, 10 views)
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 07:59 AM   #4
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
I want to the top tableview only show one row for header, bottom tableview for detail rows and scrollable.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 08:00 AM   #5
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
I'm not about to download your code and write it for you. Neither am I going to post code here for you to copy and paste: you learn nothing by simply copying; rather you learn by working it out yourself and doing. I told you exactly how what to do.
robbieduncan is offline   0 Reply With Quote
Old Jul 18, 2010, 08:05 AM   #6
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Well, I have three class, CellsAppDelegate, CellsViewController and CustomCell, can you tell me where I can define outlet?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 08:08 AM   #7
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
You need access to the outlet to compare with the parameter passed to tableView:cellForRowAtIndexPath: so I would suggest that if the instance that this is defined in is in the xib then in there. Otherwise in your controller class and pass the pointer where it is needed.
robbieduncan is offline   0 Reply With Quote
Old Jul 18, 2010, 08:49 AM   #8
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Thanks for your advise, now I got what I need.

Hope that you can continue to give better suggestion and tips
Attached Thumbnails
Click image for larger version

Name:	SnapShot 2010-07-18 at 22.48.03.jpg
Views:	14
Size:	48.6 KB
ID:	239702  
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 11:01 AM   #9
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Why do you need two UITableViews?
__________________
dejo is offline   0 Reply With Quote
Old Jul 18, 2010, 11:06 AM   #10
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by dejo View Post
Why do you need two UITableViews?
I hope there is a fixed header at top of TableView, though I can use a TextView, even so I still have to use a couple of Labels to show different header.

By the way, do you have any good idea?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 11:12 AM   #11
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Why not just take advantage of UITableView's built-in header capability?
__________________
dejo is offline   0 Reply With Quote
Old Jul 18, 2010, 11:17 AM   #12
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
I didn't know there is a header in UITableView, can that header be fixed when scroll table view rows?

Can you tell me how to use it?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 11:20 AM   #13
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Well, you might talk about section header?

That isn't what I need because that header will scroll together with data below it.

You will see My Table view has a fixed header.
Attached Thumbnails
Click image for larger version

Name:	SnapShot 2010-07-19 at 1.21.17.jpg
Views:	11
Size:	76.8 KB
ID:	239710   Click image for larger version

Name:	SnapShot 2010-07-19 at 1.21.33.jpg
Views:	9
Size:	74.8 KB
ID:	239711  
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 11:42 AM   #14
chown33
macrumors 603
 
Join Date: Aug 2009
Read the reference docs for UITableView and look for the tableHeaderView property.

Also look for UITableViewStylePlain and how it causes section headers to float, as described in the "Overview" subsection of the reference doc.
chown33 is offline   0 Reply With Quote
Old Jul 18, 2010, 12:18 PM   #15
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by chown33 View Post
Read the reference docs for UITableView and look for the tableHeaderView property.

Also look for UITableViewStylePlain and how it causes section headers to float, as described in the "Overview" subsection of the reference doc.
Thanks! I never found a sample to use this property.

Where do I set the header? in viewDidLoad? or in
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Where can I find a sample code to use this property?

Then I have a couple of cells in row, how can I set tableheader with multiple cells?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2

Last edited by mikezang; Jul 18, 2010 at 12:33 PM.
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 12:56 PM   #16
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by mikezang View Post
Thanks! I never found a sample to use this property.

Where do I set the header? in viewDidLoad? or in
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
Where can I find a sample code to use this property?

Then I have a couple of cells in row, how can I set tableheader with multiple cells?
What have you tried?

Seriously, describe what you've tried (search terms, whatever), because it was trivial to find an example and explanation simply by googling for UITableView tableHeaderView.

If you're having this much trouble simply finding things, then you need to explain exactly how you're trying to find things. Coming here for every little thing is not an effective strategy in the long term. You need to learn how to find things effectively by yourself.

There may be technical reasons why you're not finding what I found so simply. That's why you should explain exactly what you're doing.


A tableHeader is a UIView, so you can make it be anything that fits in a UIView. Did you read the doc? If you know the basics of UIView, then what to do should be obvious. It's the most basic pattern in programming: Composition. That is, building up by assembling smaller simpler components into composite structures.

If you're looking for me to provide a step-by-step complete example, I won't. Once again, you need to explain your search strategy for finding things. If everything you do needs someone to give you a complete sample on demand, then your strategy is flawed. You need to be more self-sufficient, either by learning how to write code without a complete sample, or by learning how to effectively search for samples.
chown33 is offline   0 Reply With Quote
Old Jul 18, 2010, 01:11 PM   #17
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Thanks for your Sermon・Preach・Harangue.

I googled "how to use uitableview tableheaderview to float", but I couldn't find useful information.

That would be the best if there is a complete sample code, but I just want to a sample hint for using that property.

I read almost programming guide and information at apple site, but practice is not the same as just reading, it should be not easy for new feature if there is no any sample code.

Anyway, I have to thank your for your long text, that mean you are a nice guy, but not a good teacher.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 01:16 PM   #18
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by mikezang View Post
Anyway, I have to thank your for your long text, that mean you are a nice guy, but not a good teacher.
I 100% agree with chown33. Providing people with, what they euphemistically call, sample code does not teach them anything. They copy and paste it and don't understand a single thing about what they are doing. The documentation Apple provide is excellent and is more than enough to write simple features like this without any code to steal from.

I disagree that chown33 has not a good teacher, to get you to learn on your own, to improve your abilities to use the documentation and resources that are available to you (a key programming skill) and to generally enable you to solve more advanced problems in the future. You have been a bad student in wishing to have the answer provided to you, spoon fed to you and generally all effort on your part removed.

He even provided you with a suggested Google search term that you then didn't use!
robbieduncan is offline   0 Reply With Quote
Old Jul 18, 2010, 01:21 PM   #19
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by mikezang View Post
I googled "how to use uitableview tableheaderview to float", but I couldn't find useful information.
You're using too many words.

Also, the words are unrelated. A tableHeaderView is not the element that floats. Section headers float. Read the reference docs.

If you remove the "to float", you should find an example at Cocoa With Love.


How to change your search strategy to be more effective:

1. Start with fewer words.
2. If results are too general, add a relevant word. It's an error to add an irrelevant word.
3. If results are poor quality, try removing a word. Remove less significant words first (such as "float", "use", etc.)
4. Don't stop after one search. Add or remove words.
5. Add the word "sample", "example", or "source" if you are looking for example code.

You should learn which words are relevant by reading the reference docs. That's where you should always start, so you know what terms are relevant for searching.
chown33 is offline   0 Reply With Quote
Old Jul 18, 2010, 01:36 PM   #20
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Thanks for your suggestion.

In fact, in many case, I ask here after I searched google and without a good result. But you're right, my search words might be not good enough, many times I used too words, I will try in simple key words.

Back to my detail question, I thought the two tableviews is not so bad because I can use one custom cell in both header and detail, and I can connect them to outlets in IB.

I am still not sure about tableHeaderView, but it looks like I can't use it in IB, I have to use it in programming, that is little difficult than in IB.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Jul 18, 2010, 02:35 PM   #21
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by mikezang View Post
In fact, in many case, I ask here after I searched google and without a good result. But you're right, my search words might be not good enough, many times I used too words, I will try in simple key words.
When you ask a question here, post the search terms you used. This tells us what you tried. If we see problems with your search terms, then we can suggest improvements. If you don't tell us your search terms, and they are giving you poor results, then you'll never be able to improve them and become more independent.

It's the same process as when someone says their code doesn't work, but doesn't post their code. We have no way of knowing where the problem in the code is, because we can't see the code that has the problem.

All of programming is problem-solving. An important part of solving problems is searching for existing information about solving problems. If that searching process has a problem, then you can't solve the programming problem you started to search for. This may seem obvious or even trivial, but in the long run it's fundamental. That fundamental skill is learning how to learn.
chown33 is offline   0 Reply With Quote
Old Jul 19, 2010, 11:02 AM   #22
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
mikezang, this useful blog post should help you in the future: Getting Answers
__________________
dejo is offline   0 Reply With Quote
Old Jul 19, 2010, 06:51 PM   #23
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by dejo View Post
mikezang, this useful blog post should help you in the future: Getting Answers
Thanks.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: NumberFormatter in TableView Qaanol Mac Programming 3 Dec 25, 2013 07:56 PM
parsing and displaying in tableview jennylcf iPhone/iPad Programming 2 Jan 28, 2013 06:31 AM
Populating TableView Mvkoe iPhone/iPad Programming 5 Dec 1, 2012 04:34 PM
TableView is Empty RagingGoat iPhone/iPad Programming 74 Nov 5, 2012 01:08 PM
Resolved: Help with TableView data troop231 iPhone/iPad Programming 2 Jun 26, 2012 12:49 PM

Forum Jump

All times are GMT -5. The time now is 05:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC