快速了解我的情况.UIMapView加载并显示单个注释(从不多于一个).在菜单栏上,有一个Locate Me按钮,点击查找userLocation并显示为第二个注释.然后我将MapView缩小以适应范围内的那些注释,但我无法找到合适的方法.根据第一个注释相对于用户位置的位置,有时它不会缩小.
例如,如果注释位于用户的西北方向,则会缩小范围.但是如果注释是用户的东南方,它只会缩小到足以让它们被切断,你必须手动缩小一点.这是我正在使用的代码,我在SO上找到的其他一些代码的变体.
CLLocation *whereIAm = mapView.userLocation.location;
float lat = whereIAm.coordinate.latitude;
float lon = whereIAm.coordinate.longitude;
CLLocationCoordinate2D southWest = {[currentLatitude floatValue], [currentLongitude floatValue]};
CLLocationCoordinate2D northEast = southWest;
southWest.latitude = MIN(southWest.latitude, lat);
southWest.longitude = MIN(southWest.longitude, lon);
northEast.latitude = MAX(northEast.latitude, lat);
northEast.longitude = MAX(northEast.longitude, lon);
CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];
CLLocationDistance meters = [locSouthWest distanceFromLocation:locNorthEast];
MKCoordinateRegion region;
region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
region.span.latitudeDelta = meters …Run Code Online (Sandbox Code Playgroud) 现在已经和它斗争了一段时间,不知道为什么它不起作用.
要点是将Devise与LDAP结合使用.除了自定义策略之外,我不需要做任何事情,所以除了自定义策略之外我不需要使用任何东西.
我创建了一个基于https://github.com/plataformatec/devise/wiki/How-To:-Authenticate-via-LDAP,据我所知,一切都应该工作,除非我尝试运行服务器(或rake)路线)我得到了NameError
lib/devise/models.rb:88:in `const_get': uninitialized constant Devise::Models::LdapAuthenticatable (NameError)
Run Code Online (Sandbox Code Playgroud)
我已经将错误追溯到了我的错误 app/models/user.rb
class User < ActiveRecord::Base
devise :ldap_authenticatable, :rememberable, :trackable, :timeoutable
end
Run Code Online (Sandbox Code Playgroud)
如果我删除:ldap_authenticatable然后崩溃消失但我没有路由,user#session并且无法访问登录提示.
我的支持文件:
lib/ldap_authenticatable.rb
require 'net/ldap'
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LdapAuthenticatable < Authenticatable
def authenticate!
if params[:user]
ldap = Net::LDAP.new
ldap.host = 'redacted'
ldap.port = 389
ldap.auth login, password
if ldap.bind
user = User.where(login: login).first_or_create do |user|
success!(user)
else
fail(:invalid_login)
end
end
end
def login
params[:user][:login]
end
def password
params[:user][:password] …Run Code Online (Sandbox Code Playgroud) 当引脚完成它的放置动画时,我希望弹出注释标注.目前我可以使用以下方法模拟它:
- (void)showCallOut {
[myMapView selectAnnotation:[myMapView.annotations objectAtIndex:0] animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
在我viewDidLoad的地方创建了我的注释
[myMapView addAnnotation:annotation];
Run Code Online (Sandbox Code Playgroud)
问题是你之后根本无法[self showCallOut];调用,因为在运行时它会在MapKit"确认"注释掉落之前做出响应.我需要创建一个延迟(想要避免这种情况)或者找到正确的方法来检测注释何时就位,然后运行该showCallOut方法.
谢谢你的帮助!
感谢下面的aBitObvious提供解决方案:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
[self performSelector:@selector(showCallOut) withObject:nil afterDelay:1];
}
Run Code Online (Sandbox Code Playgroud) UILabel里面的UITableViewCell.在单元格点击上,高度会扩展,并且会UILabel出现一个包含各种数据量的高度.
问题是,如果换行,sizeWithFont:constrainedToSize:lineBreakMode:则不会返回适当的高度并切断底线.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
labelExpanded = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
labelExpanded.font = [UIFont boldSystemFontOfSize:11];
labelExpanded.textAlignment = UITextAlignmentLeft;
labelExpanded.lineBreakMode = UILineBreakModeWordWrap;
labelExpanded.numberOfLines = 0;
[cell.contentView addSubview:labelExpanded];
CGSize constraint = CGSizeMake(300, 20000);
CGSize size = [expandedDetails sizeWithFont:[UIFont boldSystemFontOfSize:11] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[labelExpanded setText:expandedDetails];
[labelExpanded setFrame:CGRectMake(16, 30, 248, size.height)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(// Row is Expanded)
{
CGSize constraint = CGSizeMake(300, 20000);
CGSize size = [sameTextAsLabel sizeWithFont:[UIFont boldSystemFontOfSize:11] …Run Code Online (Sandbox Code Playgroud)