iphone programming ?. Change UITableViewCellEditingStyle image? - iphone

I just need to know is it possible to change UITableViewCellEditingStyle image ?. If possible please tell me How to do that?

I don't see any delegate methods for changing the editing-style view.
You could change the editing button title with the delegate method -tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:, however.
You could also override UITableViewCell and create a custom cell with UITableViewCellEditingStyleNone and a custom editing style behavior and appearance.

In case you're still interested you can actually get this to work by intercepting willTransitionToState and didTransitionToState in a subclass of UITableViewCell. The solution does involve "hacking" around in the cell view hierarchy. Look for the description of recursiveDescription on UIView on how to "dump" a hierarchy, but you will find a UIImageView of which you can change the .image property...
Fairly ugly hack, but does not actually use any private api.

Related

UITextView in UITableViewCell subclass, how to keep the data separate from the view

So I don't know what the best way to follow MVC is. Similar to the address books app, I want to have a UITableVeiewcell that has the ability to edit notes. I figured I would do that with a UITextView in a UITableViewCell subclass. My subclass has just that as a property, and a label that says "notes". I can see a few use cases that I need to consider,
1) when they are done editing and click outside or hit return.
2) when the text goes beyond the size of the cell I need to resize the cell.
Because my UITextView is in IB, is there a good way to define the delegate methods for the UITextView since my UITableView is in another ViewController subclass? Like how do I pass that information back?
Or, is it better to create my UITableViewCell subclass in code since it's just a couple of items so all my delegate and resizing code is done in the view controller class?
Thanks!
After text field editing was finished, you can store it's value in some dictionary in your controller. You can use cell's indexPath as key in this dictionary. In such way you will not lose your data with dequeue cells.
To resize cell you must call reloadData method and change rowHeight property of entire tableView or implement tableView:heightForRowAtIndexPath: delegate method to set needed row height to current cell.
I haven't use UIKit since iOS 3.1, so the second part of my answer can be out of date, but I hope it will help you =)

UITableViewCell Editing Minus Sign Frame?

I want to move the minus sign to the right. How do I do that?
Thanks!
I don't know if it's possible, but I'd start by looking into subclassing the UITableViewCell and overriding its layoutSubviews method.
But I don't believe you can, you only have access to the contentView, the accessoryView, the backgroundView, not the deleteConfirmationView. The closest thing you can find in UITableViewCell's reference is the boolean showingDeleteConfirmation.
So you could try subclassing the UITableViewCelland adding your own delete confirmation button where you want, by responding to willTransitionToState: when the new state is UITableViewCellStateShowingDeleteConfirmationMask.

How can I customize a UISwitch using my custom .png?

So in my code I used the setAlternateColor: method on my UISwitch to change the color to orange but my app got rejected because of this.
So I decided to use photoshop to create a custom UISwitch. Now that I have the image how am I supposed to get the UISwitch to use my custom .png?
You can't. It's probably easiest to write your own custom switch class. It's not very hard to subclass UIControl and reimplement the few things UISwitch does. (I don't know if it would also work to subclass UISwitch directly and override drawRect:. Might be worth a try.)

how do i fully customize a tableview

i want to customize my tableview, like the tipulator app for the iphone.
And heres my app:
Each UITableViewCell has a few subviews which you can replace with your own. They are:
UITableViewCell.imageView
UITableViewCell.contentView
UITableViewCell.backgroundView
UITableViewCell.accessoryView
As Gendolkari pointed out, Cocoa With Love has a great guide on custom UITableViews.
The theory is that you replace each of those views with an appropriate view to "skin" your UITableViewCells.
When replacing the background view, you check for the first and last cells when skinning the background view, otherwise you can use a "middle" background image. Implement it as a UIImageView. As far as the other views, use what you want.
Additionally, you can use a completely custom NIB file and load that in instead of the default styles provided by UIKit.
While the others are right in suggesting ways to subclass UITableView or its components, this screenshot doesn't look like it's showing a UITableView.
My guess is that they're just drawing custom images onto a background and checking certain areas for taps. What you should do is read up on the drawing methods as well as on intercepting taps and touches.
Here's a really good guide on custom styling for your table:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Create your own UITableViewCell, and use it, rather than a "generic" one.
You can do this directly in XCode with "File->New File" Then in "Cocoa Touch Class", choose "Objective-C Class" - and under the "Subclass" popup, select "UITableViewCell".
It well generate a XIB, which you can use in IB to customize the look.
Instantiate and pass-in there cells in your UITableView code, instead of the normal UITableViewCells.

Can I subclass UITableView to make it a specific style?

Basically I want to re-style UITableView(Controller). Each cell will have a picture as a background and such. this tableview will be used throughout the app thats why I want to subclass it, because I want to be able to define the style once and then reuse it everywhere, but still be able to change things per view. For instance, I'd like every cell to have the same blue background and a specific font, but I might want to change the font in one view, or make the cell taller/shorter. You get the idea.
Can I subclass UITableViewController and create the style in the methods in that? Then subclass MyCustomUITableViewController when I want to create a table view? Or would it better to subclass UITableView and then [self.view addSubview:(MyCustomTableView *)tableVie]?
Thanks
Tom
You will probably want to subclass UITableViewController to define relevant UITableViewDelegate methods, but I think that the real work will be in subclassing UITableViewCell to get the look that you want.
UITableViewCell is a UIView, so it can have a background color and it can contain a UILabel, for example.
Your -tableView:cellForRowAtIndexPath: will need to instantiate your UITableViewCell subclass (or load it from a nib) - and then configure it appropriately. I.e., setting text, image, font, etc.
Hope this helps.