supongo que está familiarizado con expresiones regulares para detectar direcciones URL, por lo que a fin de obtener uno u otro tipo de vista en su celda, simplemente puede devolver dos diferentes UITableViewCell
s de su método de tableView:cellForRowAtIndexPath:
.
Podría tener este aspecto (note por favor, escrito en el navegador no probado):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *dataString = // Get your string from the data model
// Simple pattern found here: http://regexlib.com/Search.aspx?k=URL
NSString *URLpattern = @"^http\\://[a-zA-Z0-9\-\.]+\\.[a-zA-Z]{2,3}(/\\S*)?$";
NSError *error = NULL;
NSRegularExpression *URLregex = [NSRegularExpression regularExpressionWithPattern:URLpattern
options:NSRegularExpressionCaseInsensitive
error: &error];
NSUInteger numberOfMatches = [URLregex numberOfMatchesInString:string
options:0
range:NSMakeRange(0, [string length])];
if (numberOfMatches == 0) {
static NSString *PlainCellIdentifier = @"PlainCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = timeZoneWrapper.localeName;
}
else {
static NSString *FancyCellIdentifier = @"FancyCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
// Configure cell view with text view here
}
return cell;
}
Puede ser que usted pueda verificar para 'http' en NSString, si contiene, entonces es un enlace. – rishi
@rishi, el problema es que hay muchos tipos de URL, UITextView parece detectarlos a todos, por lo que google.com, www.google.com, ... –