小编Ste*_*e N的帖子

在base64编码时删除尾随"="

我注意到每当我对base64进行编码时,最后会附加一个"=".我可以删除这个字符然后通过添加它来可靠地解码它,或者这是危险的吗?换句话说,是否总是附加"=" ,或仅在某些情况下?

我希望我的编码字符串尽可能短,这就是为什么我想知道我是否总能删除"="字符并在解码之前将其添加回来.

base64

43
推荐指数
6
解决办法
6万
查看次数

UITableView footerView带按钮,按钮不起作用

我正在尝试为我的UITableView页脚视图创建一个自定义视图,其中包含一个按钮.我可以在那里看到它,但当我触摸它时,没有任何反应......你能看出这里的错误:

- (void)viewDidLoad {
    [super viewDidLoad];

    if(self.tableView.tableFooterView == nil) {
        //allocate the view if it doesn't exist yet
        UIView *footerView  = [[UIView alloc] init];

        //create the button
        UIButton *addNewBtn = [UIButton buttonWithType:UIButtonTypeCustom];     
        //the button should be as big as a table view cell
        [addNewBtn setFrame:CGRectMake(0, 0, 320, [AddMerchantTVC cellHeight])];

        //set title, font size and font color
        [addNewBtn setTitle:@"Add New" forState:UIControlStateNormal];
        [addNewBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [addNewBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [addNewBtn addTarget:self action:@selector(addNew:) forControlEvents:UIControlEventTouchUpInside];

        UIImageView *cellGradient = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellGradient.png"]];
        cellGradient.frame = …
Run Code Online (Sandbox Code Playgroud)

iphone footer uitableview

24
推荐指数
2
解决办法
1万
查看次数

Git:如何将第三方库克隆到我应用程序库的子目录中?

我正在试图找出克隆第三方库(来自Janrain的engage.iphone)到我自己的应用程序目录结构的正确方法,这种方式可以让我提取最新的更改并将它们与我在本地进行的任何更改合并.我还希望第三方库(与我的更改合并)在我推送它时包含在我自己的应用程序的git repo中.

结构将是这样的:

myApp/  <- this is my app, which is its own git repo
    external/
        engage.iphone/ <- this is the 3rd party library I want to keep up-to-date
    mySource1.h
    mySource2.m
    ...
Run Code Online (Sandbox Code Playgroud)

如何安全地以这种方式设置它?在它成立之后,是否有任何特殊的流程可以在以后合并?

git git-clone

9
推荐指数
1
解决办法
4462
查看次数

如何调整UIImageView的大小以适应底层图像而不移动它?

我有一个UIImageView,其框架在加载图像之前设置,对于图像来说总是太大,所以当我尝试绕过角落时,没有任何反应.

我如何调整框架的大小,使其与底层图像的大小相同,同时确保UIImageView的中心点不会改变?

iphone resize uiimageview

8
推荐指数
1
解决办法
2万
查看次数

滑动和双击缩放时MKAnnotationView消失

我已经将MKAnnotationView子类化,以创建一个注释,该注释基本上通过覆盖drawRect在地图视图上的点周围绘制一个圆.在以下情况下(在模拟器中)圆圈绘制正常:

  • 在初始加载地图视图时
  • 在滑动时,但仅在触摸结束前停止滑动动作时(因此触摸结束后地图不会"滑行")
  • 捏缩放

发生以下任何操作时,圆圈将消失:

  • 在触摸结束后滑动地图"滑行"
  • 双击缩放

如果"工作"组中的任何操作在消失后进行,则该圆圈将重新出现.

什么可能导致这个?我不是抽奖/展示/布局专家(坦率地说,我也不是对象C或iPhone专家).

这是一些稍微简化的代码,它似乎与我的MKAnnotationView子类最相关:

- (void)drawRect:(CGRect)rect {
    // Drawing code
 [self drawCircleAtPoint:CGPointMake(0,0) withRadius:self.radiusInPixels andColor:self.circleAnnotation.color];
}


- (void)drawCircleAtPoint:(CGPoint)p withRadius:(int)r {
    CGContextRef contextRef = UIGraphicsGetCurrentContext();

    float alpha = 0.75;

    CGContextSetRGBFillColor(contextRef, 255, 0, 0, alpha);
    CGContextSetRGBStrokeColor(contextRef, 255, 0, 0, alpha);

    // Draw a circle (border only)
    CGContextStrokeEllipseInRect(contextRef, CGRectMake(0, 0, 2*r, 2*r));
}
Run Code Online (Sandbox Code Playgroud)

iphone quartz-graphics drawrect mkmapview mkannotation

6
推荐指数
1
解决办法
1649
查看次数

performSelector:withObject:来自类方法的afterDelay不起作用

知道为什么这不起作用吗?

[self performSelector:@selector(foo:) withObject:argObj afterDelay:5.0];
Run Code Online (Sandbox Code Playgroud)

我在一个类方法中调用它,它为同一个类调用另一个类方法(因此'self').这有效吗?

我在foo中放置了一个断点,但是没有调用它.这里发生了什么?

iphone objective-c

6
推荐指数
1
解决办法
3547
查看次数

KVO:UITableViewCell观察模型属性 - 如何在模型deallocs时取消注册?

我有一个从模型对象加载的UITableViewCells .该物业上的异步加载,我看到从它的变化知道我什么时候可以重新加载它(和替换占位符图片).这是我的问题场景:imageViewUIImagemyObjectUIImagemyObjecttableViewCell

  1. 用户执行搜索,填充模型对象数组
  2. 这些模型对象用UITableViewCells 表示,并且iconImg观察属性以进行异步下载完成.(到目前为止,这很有效).
  3. 如果用户进行另一次搜索,我会丢弃那些原始模型对象,这会导致"一个类商家的实例被解除分配,而键值观察者仍然注册了它"消息,这听起来不太好.

deallocUITableViewCell取消注册单元格的方法,但是当我dealloc在上面的场景中使用基础模型时,不会调用该方法.有没有一种干净的方法告诉我的细胞在观察到的实例时取消注册dealloc?我可以删除模型对象中的所有观察者dealloc吗?

附带问题:为什么KVO不会自动从对象中删除已注册的观察者dealloc

objective-c key-value-observing uitableview

6
推荐指数
1
解决办法
3211
查看次数

强制CLLocationManager更新 - 它有帮助还是有害?

我一直试图找到任何方法来优化基于位置的iPhone应用程序的性能,并且看到有人提到你可以通过启动和停止CLLocationManager来强制进行位置更新.我需要获得最高的准确度,我的情况下的用户可能希望在他们四处走动时每隔几秒钟(例如10秒钟)看到更新.我已经相应地设置了过滤器,但我注意到有时我在设备上没有得到任何更新.

我正在测试以下方法,该方法在固定时间间隔过去时强制更新(我使用20秒).我的直觉告诉我,这实际上无法帮助我为用户提供更准确的更新,而且只是让CLLocationManager一直运行可能是最好的方法.

- (void)forceLocationUpdate {
    [[LocationManager locationManager] stopUpdates];
    [[LocationManager locationManager] startUpdates];
    [self performSelector:@selector(forceLocationUpdate) withObject:nil afterDelay:20.0];
}
Run Code Online (Sandbox Code Playgroud)

我的问题是 - 从CLLocationManager强制更新实际上是否提高了核心位置性能?这会影响性能吗?如果我在外面有一个良好的GPS接收的开放场地,那么这会有帮助吗?有没有人有尝试这个经验?

先谢谢,史蒂夫

iphone gps core-location cllocationmanager

5
推荐指数
1
解决办法
2416
查看次数

Spring Security - 记住我的身份验证错误

我们正在使用Spring MVC并遇到与Remember Me身份验证相关的以下问题:

  1. 用户登录"记住我"选中,工作正常,persistent_login表按预期更新
  2. 我们可能在部署之后重新启动应用服务器等
  3. 用户刷新页面,我们在图1中看到错误消息,用户被重定向到登录页面(没有看到错误)
  4. 尽管有错误,但persistent_login条目令牌已更新(系列保持与刷新前相同),spring Remember Me令牌也保持相同.
  5. 用户第二次刷新页面,他们登录就像什么都没发生过一样

图1 - 错误消息

Apr 24, 2014 9:29:15 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [workmarket] in context with path [] threw exception
java.lang.ClassCastException: org.springframework.security.web.firewall.FirewalledResponse cannot be cast to org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper
at org.springframework.security.web.context.HttpSessionSecurityContextRepository.saveContext(HttpSessionSecurityContextRepository.java:99)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:139)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
at com.workmarket.web.authentication.CustomLinkedInLoginFilter.doFilter(CustomLinkedInLoginFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at com.workmarket.web.authentication.CustomLoginFilter.doFilter(CustomLoginFilter.java:100)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323)
at …
Run Code Online (Sandbox Code Playgroud)

spring-mvc spring-security remember-me

3
推荐指数
1
解决办法
2446
查看次数

Mongoose 从另一个字段的设置器更新依赖字段?

我在节点/快递/猫鼬中有一个场景,其中有积累积分的用户,当积分总数超过某个阈值时,他们会“升级”(想想基于积分的级别的游戏)。

我在点字段上创建了一个自定义设置器,用于检查值是否已更改,如果更改则尝试更新级别字段。级别在另一个集合中定义,但在与用户文档关联时保存为简单的 JSON 对象(因此查询中的 .lean() )。为了提高效率,我这样做了,而不是虚拟领域或群体。

问题:这实际上似乎并没有在应该更新用户“级别”字段时更新。我究竟做错了什么?

// Define our user schema
var UserSchema = new mongoose.Schema({
    ...
    points:       {type: Number, default: 0, set: pointsChangeHandler},
    level:        {name: String, minPoints: Number, maxPoints: Number},
    ...
});
Run Code Online (Sandbox Code Playgroud)

设置器看起来像这样:

function goodPointsChangeHandler(newValue) {
    var self = this;
    if (newValue != self.goodPoints) {
        console.log('Point change detected.');
        // Find level that corresponds with new point total
        Level.findOne({
            'minPoints': {$lte : self.goodPoints},
            'maxPoints': {$gt : self.goodPoints}}, '-_id').lean().exec(function(err, level) {
            if (self.goodLevel == undefined || self.goodLevel.rank != level.rank) { …
Run Code Online (Sandbox Code Playgroud)

mongoose node.js

2
推荐指数
1
解决办法
2801
查看次数

获取MYSQL记录的合理随机密钥的最佳方法

我需要为表生成一个合理随机的唯一键.它应该类似于MYSQL的GUID.我尝试过UUID,但看起来只有前几个字符实际上是随机的 - 其余的每次插入时都是一样的.

基本上,即使您已经在列中具有一个已知值,也希望此关键字段很难猜测.

执行此操作的最佳方法是什么,以及如何设置字段数据类型以有效地存储值?

谢谢,史蒂夫

mysql sql security random guid

0
推荐指数
1
解决办法
1356
查看次数