It looks like you're new here. If you want to get involved, click one of these buttons!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UIImageView *balloonView;
UILabel *label;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
balloonView = [[UIImageView alloc] initWithFrame:CGRectZero];
balloonView.tag = 1;
label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.tag = 2;
label.numberOfLines = 0;
label.lineBreakMode = UILineBreakModeWordWrap;
label.font = [UIFont systemFontOfSize:14.0];
UIView *message = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, cell.frame.size.height)];
message.tag = 0;
[message addSubview:balloonView];
[message addSubview:label];
[cell.contentView addSubview:message];
}
else
{
balloonView = (UIImageView *)[[cell.contentView viewWithTag:0] viewWithTag:1];
label = (UILabel *)[[cell.contentView viewWithTag:0] viewWithTag:2];
}
NSString *text1 = [messages objectAtIndex:indexPath.row];
CGSize size = [text1 sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:CGSizeMake(240.0f, 480.0f) lineBreakMode:UILineBreakModeWordWrap];
UIImage *balloon;
if(MESSAGE RECEIEVED)
{
balloonView.frame = CGRectMake(0.0, 2.0, size.width + 28, size.height + 15);
balloon = [[UIImage imageNamed:@"grey.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
label.frame = CGRectMake(16, 8, size.width + 5, size.height);
}
else
{
balloonView.frame = CGRectMake(320.0f - (size.width + 28.0f), 2.0f, size.width + 28.0f, size.height + 15.0f);
balloon = [[UIImage imageNamed:@"pink.png"] stretchableImageWithLeftCapWidth:24 topCapHeight:15];
label.frame = CGRectMake(307.0f - (size.width + 5.0f), 8.0f, size.width + 5.0f, size.height);
}
balloonView.image = balloon;
label.text = text1;
return cell;
}
Replies
2. From what I gather here, the messages array contains only strings. This means you are not keeping enough information about a given message. You will need to make a model object (see link in my signature) that keeps track of not only the message text, but whether it was incoming or outgoing. And then perhaps sender ID, time stamp, etc. So, most of the work needs to be done wherever you are processing messages, not here. Here will just be a matter of looking at the property and displaying accordingly.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMy conditional is inside the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; I am a total newbie.
My code is below: My conditional is inside - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; method so I don't know how to implement that method. Please I really need help.
I'm sorry if this is a total newbie question. iOS programming is also my first programming language and everyone tells me it is harder than the rest. I hope you guys understand.
Thanks,
AD
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNow then, while I'm sure you're being honest about being a newbie, it's also a cop-out. You're messing with game kit and blue tooth, skills that I don't currently have. So either you know more than you are letting on, or all you have done so far is copy-paste stuff from other tutorials. You cannot copy-paste your way into being a good coder. At some point you have to take the time to understand this stuff.
No one here has a problem with helping you learn, but nobody is going to just hand you code so that you can go on your way until you smack into the next problem. Asking questions that demonstrate that you are trying to learn will get you a lot farther than simply asking the same question over and over again.
So, I suggest you reread my previous answer, go read the thread I linked to you, put some good honest thought into a solution, and then if necessary come back and ask specific questions about the technique.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI just want to clarify and I'm sorry about before.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhat you want is a simple model object along these lines: If that is all you need, then you can stop here. If you need more, add more. Perhaps a date property for the message sent date/time. Perhaps a string property to identify the sender.
Then your code would become: And then to demonstrate why the previous answer was insufficient, here is how you might use it with your model object: Before, all you had was a string to represent each message. All the string provides is the body, it does not provide any other information. Now, you have the extra property, and can store that value. Pretty much the only way you could have made this method work with your previous structure would have been to use two separate arrays: Using the model object is a better approach for a variety of reasons. Either way, the method you were given before could not have been used by itself without you making additional changes of some kind. That's why you should not ask how to shoehorn a particular method into a specific part of your app. It may not make sense in that spot, it may not make sense at all, and even if it does make sense, you may have to make adjustments in order to utilize it.
But at the end of the day, you learn the most by trying. There is never a reason to come here and ask if code would work. Try it for yourself, then you will know. If it does work, then you don't need to worry too much at this stage whether or not it could be better. Those things come with experience. If it doesn't work, then you need to decide if you feel like it should work, and then you can ask those kinds of questions. Here is what I expected, here is what I did, but unfortunately here is what happened, this is not what I expected, what does this mean?
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome2012-08-24 14:23:02.698 iVoiceChat[88604:207] -[__NSCFString isReceived]: unrecognized selector sent to instance 0xe02d6b0
2012-08-24 14:23:02.700 iVoiceChat[88604:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString isReceived]: unrecognized selector sent to instance 0xe02d6b0'
*** First throw call stack:
(0x1f36022 0x1c21cd6 0x1f37cbd 0x1e9ced0 0x1e9ccb2 0x54ae 0x4eec54 0x4ef3ce 0x4dacbd 0x4e96f1 0x492d42 0x1f37e42 0x13f1679 0x13fb579 0x13804f7 0x13823f6 0x1381ad0 0x1f0a99e 0x1ea1640 0x1e6d4c6 0x1e6cd84 0x1e6cc9b 0x17797d8 0x177988a 0x454626 0x1db8 0x1d15)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
(gdb)
The code you gave me for the object header I kept the same and for the implementation file I just synthesized the variables. The concept of model objects is a little bit hard for me to grasp. I am going to add a date method in the future once I get a little bit better understanding of models by reading books and using google.
Thanks, and I just want to say I really appreciate your help,
AD
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhen you receive NSData from your remote host:
Convert the data to a string
Create an ADMessage object
Install the string into the ADMessage object
Save the ADMessage object to your array.
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHow do I set the value of the ADMessage Object to the value of the string.
I'm a little confused there. Just in case you need my send data method here it is. I haven't added the ADMessage Object to the send method yet.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeNow I just have to test it.
Here is my code:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere is my code: I'm thinking that I would need to do something like this:
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDon't call your data object "text". It is not text, it is a data object that has a string property. That's going to confuse you, and anybody who works on your code in the future. Call it something like cellData.
If you have an ADMessage object called cellData, you'd get to the messageBody property with the expression cellData.messageBody
Duncan C
WareTo
Animated GIF created with Face Dancer, available for free in the app store.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome2012-08-24 20:27:29.809 iVoiceChat[12491:207] -[ADMessage sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x92471d0
My code is below and I have absolutely no idea what I'm doing wrong. Thanks,
AD
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks,
AD
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
1 • Off Topic 1Insightful Disagree Dislike Like AwesomeRight now my code looks like this. What would I have to change?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomereceived was defined as a BOOL, which means YES or NO. That was just a suggestion, there are lots of ways to accomplish the goal, but this one is simple enough. If (isReceived == YES), then what does that mean? Means the message was incoming. If (isReceived == NO), then what does that mean? Means the message was outgoing. So you need to provide appropriate values at the proper times.
But seriously, use your head. You need to distinguish between incoming and outgoing messages. How should you do that? Doesn't matter. How do you want to do that? What makes sense for you? You could use a BOOL as I indicated. You could use a string: You could use a number: There are lots of options. So pick something that you like, and go with that. After you make that decision, then you have to supply the corresponding value at appropriate times. Then check the value later to decide what to do for different conditions.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome