Why not work my UITableViewCell Subclass? - ios

I'm trying to make a TableView with a CustomCell, I get the data of a XML web service, I'm parsing whole fine, but when I like show the data in my UITableViewCell subclass only can see the image, the labels not appear, I have the Oulets and instances correctly but just it not work .
Respository with the code
I leave a bitbucket repository to check my code, please help me, I think that is a small error but is hard to solve to me.
Thanks in advance.

Your labels begin with a newline character, for example:
__NSCFString * #"\n Casas de empeño ‘exprimen’ a deudores" 0x08cb7c10
You can solve this by trimming white space:
cell.cabezaLbl.text = [[dic objectForKey:#"Cabeza"] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

NSString *str = [dic objectForKey:#"Entrada"]
str is like "\n bla bla bla" so your label should be show multiple lines. You should set numberOfLines property of this label 0.
cell.entradaLbl.numberOfLines = 0;
Or you can do this in interface builder.

Related

"ԅ" causing iOS app crash

I find that if I set UILabel's text to "ԅ", it crashes without further information. It didn't hit the "All Exception" breakpoint.
self.label.text = #"ԅԅ";
How do I get rid of this crash? Thank you in advance!
By the way, I found this problem due to an emoticon "ԅ(¯﹃¯ԅ)", which kind of describes what I'm feeling right now.
Do not pass directly a Unicode character to NSString initialisation, instead use the character's Unicode code-point representation. In case of this character, it'd be #"\u504".
try this:
NSData *strd = [text dataUsingEncoding:NSUTF16StringEncoding];
NSString *newStr = [[NSString alloc] initWithData:strd encoding:NSUTF16StringEncoding];

Get Rid of Line Breaks UITextView

For the past few hours I have been trying to get rid of all the visible line breaks that my UITextView is showing. So I thought it would be as simple as running this code:
NSString *trimmedString = [textView.text stringByReplacingOccurrencesOfString:#"\n" withString:#""];
[textView setText:trimmedString];
However, it seems like nothing changes after executing that. The textView text is in fact being set to trimmedString but the line breaks are still visible like shown in the picture below.
How would I properly fix this so I can have the text shown in the image (as an example), be without line breaks?
I just put your example code in the viewDidLoad of my UIViewController and totally saw the expected result. Here is one screenshot without your code snippet:
And here is a screenshot with the code snippet:
You can see that the line breaks were replaced. Did you connected your UITextView Outlet correctly ?
I fixed it with this code:
NSString *trimmedString = [textView.text stringByReplacingOccurrencesOfString:#"\r\n" withString:#" "];
[textView setText:trimmedString];

Loop in a variable of type IBOutlet

I have twelve text fields as you can see below:
IBOutlet UITextField *ce_1;
IBOutlet UITextField *ce_2;
IBOutlet UITextField *ce_3;
....
IBOutlet UITextField *ce_12;
All I have to do is to set an existing object in an array in each of the variables that are responsible for the text fields, I'm currently doing as follows:
ce_1.text = myArray[1];
ce_2.text = myArray[2];
ce_3.text = myArray[3];
....
ce_12.text = myArray[12];
Not to be writing a lot, I thought I'd put this in an automated way within a loop as follows:
for(i=1;i<13;i++){
ce_[i].text = myArray[i];
}
But this command does not work the way I expected, so I would like your help to try to solve my idea and put it into practice, is there any way of doing this?
Research and start using IBOutletCollection. It will give you an array of text fields that you can build in your storyboard XIB.
Note that you may need to consider the order of the array, and that you might want to sort it (possibly based on the tag of each view).
Technically, you could use string formats and KVC to do what you're currently trying to but it is far from ideal.
You can't just replace ce_1 ce_2 ce_3 with ce_[i] it doesn't work that way. You can only use [number] with an nsarray variable (or decendents).
for example:
NSArray* myArray = #[#1];
NSLog(#"%#", myArray[0]);
You might want to look into IBOutletCollection in order to achieve something similar to what you're looking for.
However, contrary to other answers here IBOutletCollection are ordered by how you link them in the interface builder.
Refer to this for IBOutletCollections: How can I use IBOutletCollection to connect multiple UIImageViews to the same outlet?
You can use IBOutletCollection. You can also use key-value coding:
for(NSUInteger i = 0; i < 13; i++)
{
[[self valueForKey:[NSString stringWithFormat:#"ce_%u", i]] setText: myArray[i]];
}
This will give you what you want.
The way I like to handle these situations is creating a temporary array containing all the text fields:
NSArray *allFields = #[_ce_1, _ce_2, _ce_3, ...];
NSInteger i = 0;
for (UITextField *tf in allFields)
{
tf.text = myArray[i];
i++
}
IBOutletCollection also work but sometimes it gets hard to figure out when you come back to your project which label is #3 or #5 and such... I find this works better for me usually :)

iOS: Column formatting for NSString not working in UITextView?

I'm working on an iPad app and I need to be able to format some output on the screen in a columnar format. This was similar to my question:
How can I use the \t [tab] operator to format a NSString in columns?
and I used that solution, unfortunately I'm not seeing the same results. My code is as follows:
NSString* titleColumn = [[NSString stringWithFormat:#"%#", displayName] stringByPaddingToLength:25 withString:#" " startingAtIndex:0];
NSString* serializedValue = [[NSMutableString alloc] init];
NSString* valueAsString = [NSString stringWithFormat:#"%.03f", value];
serializedValue = [serializedValue stringByAppendingFormat:#"%#%#", titleColumn, valueAsString];
When logging the items in the console, they are properly aligned, however, when plugging them into a UITextView, they are misaligned. This is how I'm sticking them in the text view:
NSMutableString* displayString = [[NSMutableString alloc] initWithString:#""];
for (NSString* entry in textToDisplay)
{
NSLog(#"%#", entry);
[displayString appendString:entry];
[displayString appendString:#"\n"];
}
[self.fTextPanel setText:displayString];
Any ideas on what I'm doing wrong?
EDIT:
In the log, it looks like this:
Inclination 0.000
Version 0.000
Inferior/Superior 0.000
Anterior/Posterior 0.500
And the UITextView version looks like this: http://imgur.com/vrUzybP,OYxGVd8
The reason for misaligned is the different width for each character. The best way for displaying this type of information is by using UITableView, You can use title and subTitle field for displaying or you can design a custom UITableView.
the reason is because when drawing charachters (glymphs), each character will have different widths,i.e character small c and big C will take different widths for drawing , so it wont work. Even though there are two strings with equal lengths but different characters, the drawing text will have different widths.
What i would suggest you for this is to have two textViews side by side, render titles in one textVIew and values in the next TextView.
If the number of titles is large and if you enable scrolling in textVIews, use delegate Methods of UIScrollView, and when scrollHappens in either of them, set the contentOffset of the other to make it look like single TextView.
Hope this helps.

Replace lines of text in iOS

I am needing to replace a line of text in code on my iOS app, however the lines that need to be replaced in the particular NSString will be different for different entries on the XML that is being parsed.
For example, I need to replace 129727-the-cave.mp3 with 129727.jpg.
However, I can't just tell it to replace -the-cave.mp3, because some instances of the string will have a different number and title of mp3. I think the next line is:
129838-my-song.mp3.
So, basically, I need a way to find everything from the first hyphen through mp3 and replace it, no matter what the text is?
Try this:
NSString *original = #"129727-the-cave.mp3";
NSString *sub = [original substringToIndex:[original rangeOfString:#"-"].location];
NSString *finalString = [sub stringByAppendingString:#".jpg"];
NSLog(#"finalString: %#", finalString);

Resources