Make UIWebView part of UITableviewCell - objective-c

I need to make UI like following:
In response to a HTTPRequest, I am getting JSON response.
Title & Some HTML Content.
I fill UITableViewCell with the title i get in response.
Now, I need to display the HTML Content in a dropdown manner, with UITableViewCell. Means, on tapping on cell It appears below the cell (or say, in the cell) and tapping again will make it disappear.
I am thinking of making UIWebView, a part of UITableViewCell. Any guidance on how to achive that.
And also, Is there any better way to perform this?

As you asked, "And also, Is there any better way to perform this?"
Not better I can say, but
In my case, I did it using different approach.
on didSelectRowAtIndexpath: I set up new UIWebView and showed the HTML content in it.
I really searched the web for setting the height of UIWebView dynamically, as per the content I am getting through WebResponse. But, I didn't found anything useful, really.

You can try dynamically inserting and removing custom cell which holds UIWebView below cell you select on didSelectRowAtIndexPath:. But I strongly suggest you find a way to convert HTML into string (NSAttributedString, for example) and show a label. UIWebView is known for killing performance.

Related

UITableView Cell - Edit?

Is it possible to use a UITableView to be able to enter a value into a database's field.
For example, if I was to have a UITableView pointing to a field within a database and if I wanted to enter a new entry into the database - tap on the UITableView Cell that would then allow keyboard input into the cell which ultimately end up being a new record in the database??
This is possible, but if something is possible doesn't mean you should be doing so.
You might ask why?
Well! you are trying to input data from view directly to database, this is a very bad practice. There are many reason for it being bad, the major is efficiency and security reasons.
You should consider using MVC pattern.
Now since its completely possible, I will explain the idea on how to do it and conclude with links that will have real code examples.
In tableView:cellForRowAtIndexPath:
add a TextField with tag (to get the reference back in future) and add it to contentView of the cell and have it hidden.
Now in tableView:didSelectRowAtIndexPath: make the cells editing property to YES.
Then, in tableView:willBeginEditingRowAtIndexPath:
get the reference to the textfield in contentview using viewWithTag: method and hide the textLabela and unhide the textfield.
In textfield's delegate textFieldDidEndEditing: make cell's editing property as no (yea, you need to keep the reference) unhide the textlabel and hide textfield.
In tableView:didEndEditingRowAtIndexPath: write methods which will commit the changes to your db.
Below are list of links which will get you code examples:
Having a UITextField in a UITableViewCell
Accessing UITextField in a custom UITableViewCell
iOS Database Tutorial
There are no examples for your requirement 'coz it bit bad way of doing things.
Yes its possible....
You can use delegate methods to take data form you cells textfield to your parent view controller and then save data in database.

Is there a way to display a different small image (icon) for each row of a NSTableColumn?

Is there a way to display a different small image (icon) for each row of a NSTableColumn ?
I don't necessarily need to add a new column for it, I was wondering if I can just add the icon in front of the text of each row.
I know there is the method: - (void)setDataCell:(NSCell *)aCell . However this method seems to use the same cell for all rows, which is not what I want.
Is there a solution to this problem which doesn't require to subclass the NSTableColumn ? If not, what should I subclass ?
thanks
Make the cell for the column in question an NSImageCell. You can do this in Interface Builder by dragging an "Image Cell" from the object library onto the column. Then select the column and you'll be able to bind to an image source via one of the Data, Value, Value Path, or Valueurl bindings. Which one you choose depends on whether the source property in your model returns NSData, NSImage, NSString path, or NSURL url, respectively. See the documentation on NSImageCell bindings for more complete information.
Cells are the same for each row, because they're a lightweight class used as a performance optimization for drawing. That doesn't mean that each row has to use the cell to draw the same image though, any more than the text columns' cells have to draw the same string for each row.
If you really need the image to be in the same column as text, you'll have to do something more like duDE explains. Off the top of my head, I believe bindings should be still possible in this case, but you'll have to write more code to make that work. Rather than do that, I would probably switch to using a view based NSTableView, which makes putting multiple views in a single column/row easy, and will let you continue to use bindings without any extra work.
EDIT: duDE's answer was deleted, but to summarize, it suggested creating a custom NSCell subclass that would draw both an image and text.

UILabel UITextView

I'm stuck in a problem now,I want to get the text be selectable,but the text had been put into a UILabel,so currently it's impossible for me to select,change the UILabel to UITextView is not a good choice for me now,since i just maintain the old code and only can make some little change on it,but the latest command need me to implement this function on UILabel,so anybody get any idea .or just give me some little instruction maybe good enough,thanks a lot
Getting the word touched in a UILabel/UITextView
is not helpful
You need to switch to a UITextView or UITextField. It will be a smaller, easier change than trying to re-implement the selection UI that those classes already implement. You can make the text view (or field) selectable but not editable by setting the view's editable property to NO.

Detect taps of links/numbers in UITextView

theres no way to detect weather the user taped on a phone number and/or link in a UITextView is there?
There doesn't seem to be a delegate method for it.
Any ideas?
You cant with UITextFied, but if you use a webview and get it to load a string with html tags for links, you can use the should load method to detect whats doing.

Making normal tableview cell's text to be on the top instead of being in the middle

Hey I need a fairly large cell to show my information, but when I put text in it, the text starts from middle weirdly, how can I make it so, that it starts from the top?
Thanks in advance!
I recommend you that you use a custom UITableViewCell so you can place the elements wherever you need them to be. Here you have a couple of links that will help you do so:
Custom UITableViewCell using Interface Builder
Creating Custom UITableViewCell Using Interface Builder
I hope it helps,
Regards